Solved

Convert decimal to time

Posted on 2004-04-08
5
1,164 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 50 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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