?
Solved

Convert decimal to time

Posted on 2004-04-08
5
Medium Priority
?
1,170 Views
Last Modified: 2008-02-01
Hello All

I want to be able to grab a number, anything from 0.016666 to 86399.999999
and convert it to a time

For example:

0.50 = 30 seconds or 00:00:30 and 00:30
1.50 = 1 minute, 30 seconds or 00:01:30 and 01:30
197.50 = 3 hours, 17 minutes, 30 seconds or 03:17:30 and 197:30

I can do the calculations by hand (on a calculator) but can't get my head around the code or the formatting of the end figure.

Can someone please help

Dahquim
0
Comment
Question by:dahquim
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
mmusante earned 150 total points
ID: 10783033
If the number N is expressed in minutes ...

format(N/1440,"hh:nn:ss")
0
 

Author Comment

by:dahquim
ID: 10783112
Thanks for the reply
This works great, i feel so dumb for not realising this.

However, how do i do the second part

so 03:17:30 = 197:30

Would it be just  case of taking the hours multipling by 60 and then adding the minutes?

Thanks for the help

Dahquim
0
 

Author Comment

by:dahquim
ID: 10783195
I have sorted it, thanks for the help.

Dahquim
0
 
LVL 6

Expert Comment

by:mmusante
ID: 10783212
Yas for Min:Secs format, to have back the minutes-with-decimals format try this ...

cdbl(#03:17:30#)*1440
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10783226
try this:

1) convert the number to Seconds

Dim Seconds As Long
Dim Number As Double

Number = Text1.Text

Seconds = Number * 60

2) then conver the number of seconds into Days, Hours, minutes and seconds in that order:
Dim Days As Long
Dim Hours As Long
Dim Minutes As Long

Days = Fix(Seconds / 86400) '86400 seconds in 1 day)
Hours = Fix((Seconds - Days * 86400) / 3600) ' 3600 Seconds in 1 Hour
Minutes = Fix((Seconds - Days * 86400 - Hours * 3600) / 60)
Seconds = Seconds - Days * 86400 - Hours * 3600 - Minutes * 60
Text2 = Days
Text3 = Hours
Text4 = Minutes
Text5 = Seconds


AW
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question