Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Time to a Number

Status
Not open for further replies.



The Date/Time Value is in units of DAYS, so merely convert days to hours by taking the product of Time days and 24 hrs per day.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
How are ya LouieGrandie . . .

[blue]2:00 pm[/blue] is actually [blue]14:00 hrs[/blue] in military time (24hr). A simple format does the trick:
Code:
[blue]   Debug.Print Format(#2:00 pm#, "[purple][b]Hh:Nn[/b][/purple]")[/blue]

48 mins is 80% or 0.8 of one hour. Surely the math for this is plain ... I just don't see the need for such an display format ...

Perhaps if you supplied more data points it would become more plain.

10:00 am = [blue]?[/blue]
11:00 am = [blue]?[/blue]
12:00 am = [blue]?[/blue]
1:00 pm = [blue]?[/blue]
2:00 pm = 14:00

9:48 AM = 9.80
9:48 PM = [blue]?[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Code:
Public Function decimalTime(dtm As Date) As String
   decimalTime = Format(Hour(dtm) + Minute(dtm) / 60, "0.00")
End Function

test
Code:
Public Sub testdtm()
 Debug.Print decimalTime(#2:00:00 PM#)
 Debug.Print decimalTime(#9:48:00 AM#)
 debug.print now
 Debug.Print decimalTime(Now)
End Sub

results
Code:
14.00
9.80
5/25/2012 2:15:52 PM 
14.25
 
Why not just multiply the time value by 24.
I thought the OP's requirement was for a formatted two decimal place solution.
OP said:
2:00PM and convert it to 14.00 or 9:48AM to 9.80
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top