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

subtracting times

Status
Not open for further replies.

jm314

Technical User
Sep 7, 2004
23
US
When taking the difference between 2 times, how can I turn the value back into a time-formated string? for instance:

time1 = now
time2 = now
tdif = timevalue(time1) - timevalue(time2)

timevalue seems to use/return a double precision float. how do I convert the value of tdif to a time format string like 00:00:00 ?
 
Format(tdif, "hh:mm:ss")

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 

Hi,

Since you're calculating Elapsed Time rather than a Time-of-day value...
Code:
Format(tdif, "[h]:mm:ss")
That way, elapsed time values that exceed ONE DAY (24 hrs), will format as HOURS greater than 24.

Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
TimeValue normally takes a string.

Code:
Dim t1
Dim t2
t1 = Now
MsgBox "gimme a sec"
t2 = Now
MsgBox Format(t2 - t1, "hh:mm:ss")

will give you the difference in time ("00:00:02" in my case), even though the variables contain full date values.

TimeValue returns a value between 00:00:00 and 23:59:59, so if you use TimeValue in the above:
Code:
Dim t1
Dim t2
Dim t3
t1 = Now
MsgBox "gimme a sec"
t2 = Now
t3 = t2 - t1
MsgBox TimeValue(Format(t3, "hh:mm:ss"))

it will return "12:00:02" - as I have my system set up as 12 hour, rather than 24 hour.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top