6 Replies Latest reply on Oct 22, 2010 11:48 AM by philmodjunk

# Get Total Hours between Total Days, Time Start and Time End

### Title

Get Total Hours between Total Days, Time Start and Time End

### Post

Here are the example:

Date Start : 8/24/2009

Date End : 8/26/2009

Total Days : 3

Start Time :  7:45:00 AM

End Time :   4:30:00 PM

Gives result of

Total Hours : 24 hours 135 minutes

Below is the calculation:

Total Hours = (Total Days) * Hour(Time End - Time Start) & (If (Hour (Time End - Time Start) = 1; " hour, "; " hours ")) & (Total Days) * Minute(Time End - Time Start) & (If (Minute (Time End - Time Start) = 1; " minute "; " minutes "))

I can't figure out how to subtract the difference in hours and minutes.

• ###### 1. Re: Get Total Hours between Total Days, Time Start and Time End
IMHO, the total time elapsed in your example is 56:45:00, which can be calculated simply by =

Timestamp ( EndDate ; EndTime ) - Timestamp ( StartDate ; StartTime )

From this you can easily extract the hours, minutes and seconds using the corresponding functions.

• ###### 2. Re: Get Total Hours between Total Days, Time Start and Time End
Ok. How to state the total hours into 00 hours 00 minutes format instead of 00:00:00?
• ###### 3. Re: Get Total Hours between Total Days, Time Start and Time End

As I said, use the Hour(), Minute() and Seconds() functions to extract the elements, e.g.:

`Let ( [elapsed = Timestamp ( EndDate ; EndTime ) - Timestamp ( StartDate ; StartTime ) ] ;SerialIncrement ( "00" ; Hour ( elapsed ) ) & " hours " & SerialIncrement ( "00" ; Minute ( elapsed ) ) & " minutes" )   `
• ###### 4. Re: Get Total Hours between Total Days, Time Start and Time End

I am looking to do the same thing.  I want a field to display "X Hours XX Minutes".  Currently, my calculation outputs "5.73 Hours".  My existing calculation is:

((Day01Exit05 - (If ( Day01Exit05 = "" ; "" ; Day01Entry05))) + (Day01Exit04 - (If ( Day01Exit04 = "" ; "" ; Day01Entry04))) + (Day01Exit03 - (If ( Day01Exit03 = "" ; "" ; Day01Entry03))) + (Day01Exit02 - (If (Day01Exit02 = "" ; "" ; Day01Entry02))) + (Day01Exit01 - (If ( Day01Exit01 = "" ; "" ; Day01Entry01))))/3600

All the fields referenced in the calculation are timestamps.  Any simple modifications I can make to this script so it will display hours and minutes instead of hours with a decimal?

• ###### 5. Re: Get Total Hours between Total Days, Time Start and Time End

Here's a calculation, all you need to do is substitute '\$duration' with a value in minutes:

Case ( \$duration > 59; Div ( \$duration; 60 ) & " Hours " ) & Case ( Mod ( \$duration; 60 ) <> 0; Int ( Mod ( \$duration; 60 ) ) & " Minutes" )

• ###### 6. Re: Get Total Hours between Total Days, Time Start and Time End

Another option, if you don't need the actual words "Hours, minutes and seconds", is to simply choose time as your result type for the calculation and use inspector to format the field with an HHMMSS, 24 hour format.