There are quite a few different formulas/solutions for this issue- here are a few:
Follow these steps to calculate the time between two dates in "hh:mm:ss" format:
1. Create a variable called <Days_into_Seconds>. This will calculate the days between and converts then into seconds:
[code]
=(DaysBetween(<BeginDate>,<EndDate>) * 24 * 60*60)
[/code]
2. Create a <Start Seconds> variable for the "BeginDate":
[code]
=(ToNumber(FormatDate(<BeginDate > ,"HH"))*60) +(ToNumber(SubStr(FormatDate(<BeginDate > ,"HH:mm") ,4 ,2))) *60 +(ToNumber(SubStr(FormatDate(<BeginDate> ,"HH:mm:ss") ,7 ,2)))
[/code]
3. Create a <End Seconds> variable for the "EndDate", but this time adding the <Days_into_Seconds> to this as well:
[code]
=((ToNumber(FormatDate(<EndDate > ,"HH"))*60) +(ToNumber(SubStr(FormatDate(<EndDate > ,"HH:mm") ,4 ,2))) *60)+(ToNumber(SubStr(FormatDate(<EndDate> ,"HH:mm:ss") ,7 ,2))) + <days into seconds>
[/code]
4. Subtract them to get the difference between these two dates (call this variable <Seconds Difference>) in seconds.
[code]
=<End Seconds>-<Begin Seconds>
[/code]
5.To convert this to "hh:mm:ss" format, use the following formula:
[code]
=FormatNumber((Floor(Truncate((<Seconds Difference> / 3600) ,0))) ,"00")+":"+FormatNumber((Floor(Truncate(Mod(<Seconds Difference> , 3600) , 0) / 60) ) ,"00")+":"+FormatNumber(Floor(Mod(Mod(<Seconds Difference> , 3600) , 60) ) ,"00")
[/code]
You retrieve two date objects from your database and want to calculate the number of minutes between them.
To calculate the difference between to date objects and :
Number of day:
<Days>=DaysBetween(<Date1> ,<Date2>)
Number of Hours:
<Hours>=ToNumber(SubStr(FormatDate(<Date1> ,"HH:mm:ss") ,1 ,2))- ToNumber(SubStr(FormatDate(<Date2> ,"HH:mm:ss") ,1 ,2))
Number of Minutes:
<Min>=ToNumber(SubStr(FormatDate(<Date1> ,"HH:mm:ss") ,4 ,2))- ToNumber(SubStr(FormatDate(<Date2> ,"HH:mm:ss") ,4 ,2))
Number of Seconds:
<Sec>=ToNumber(SubStr(FormatDate(<Date1> ,"HH:mm:ss") ,7 ,2))- ToNumber(SubStr(FormatDate(<Date2> ,"HH:mm:ss") ,7 ,2))
You can display the full result:
In seconds:
=<Sec>+<Min>*60+<Hours>*3600+<Days>*86400
In minutes:
=<Min>+<Hour>*60+<Days>*1440
In text format:
= FormatNumber(<Hours>+24*<Days> ,"0")+"Hour(s) "+ FormatNumber(<Min> ,"0")+" Minute(s) "+ FormatNumber(<Sec> ,"0")+" Second(s) "
To compare a date with the current date, you can use the functions CurrentDate() and CurrentTime():
<Hours>=ToNumber(SubStr(FormatDate(<Date1> ,"HH:mm:ss") ,1 ,2))- ToNumber(SubStr(FormatDate(CurrentTime(),"HH:mm:ss") ,1 ,2))
---
**Reporter Bloke** :uk: _(BOB member since 2004-05-20)_