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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Time to Number

Status
Not open for further replies.

gavjb

Technical User
Jul 5, 2005
67
GB
I am trying to convert a Time to a Decimal Value, but I am after rounding it by 5 minutes (so for example if I had 01:31:00, it would give me 1.5). So far I have managed to convert to a number with:

format$(CDbl(#01:47:00#) * 24,"0.00")

But not to clear on the easiest way to finish this off.

Thanks,


Gavin,
 
Suprisingly tricky. Here's a starting point
Code:
Dim t                           As Date
Dim n                           As Integer
Dim t1                          As Date
Dim s                           As Long
Dim s1                          As Long
t = TimeValue(#3:00:27 AM#)
For n = 0 To 60
    t1 = DateAdd("n", n, t)
    s = Minute(t1) * 60 + Second(t1)
    s1 = (s + IIf(s Mod 300 >= 150, 300, 0)) \ 60
    s1 = s1 - s1 Mod 5
    Debug.Print t1, TimeSerial(Hour(t1), s1, 0), _
                Format(CSng(Hour(t1)) + (CSng(s1) / 60), "0.00")
Next

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top