Trouble adding hours to a total greater than 24

1. Junior Member
Join Date
Dec 1969
Posts
11

## Trouble adding hours to a total greater than 24

I simply want to be able to keep track of the number of hours someone has worked, and be able to add something like 22:45 + 8:30 and get 31:15. Any help would be much appreciated, thanks<BR><BR>Olly

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## Use floats

3. Senior Member
Join Date
Dec 1969
Posts
2,930

## why not

use Doubles to store the Hours Worked, instead of a time? <BR><BR>e.g. when someone logs in 8 hours and 30 minutes... store this as 8.5 hours, and 22 hours and 45 minutes would be 22.75 hours... this added up will be 31.25 simple.<BR><BR>otherwise you can do some major conversions and splits and more conversions and additions...

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## Wow, wish I'da thought of that

Oh wait, I did, 5 minutes ago...<BR><BR>:)

5. Junior Member
Join Date
Dec 1969
Posts
11

## maybe

I thought of splitting the time into minutes and hours, but wondered if there was a way to keep minutes as 15, 30 etc instead of 25, 50.<BR><BR>Thanks anyway

6. Senior Member
Join Date
Dec 1969
Posts
2,930

## you were very

brief... no help to anyone... ;-)

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Pardon me guys...

...but date/time values *ARE ALREADY* Doubles!<BR><BR>So:<BR><BR>&#060;%<BR>myTime = TimeSerial( 8, 15, 0 ) &#039; 8 hrs. 15 mins.<BR>dTime = CDbl( myTime ) &#039; dTime will be 8.25<BR>%&#062;<BR><BR>Since you can go back and forth between date/time and double values at will, it really matters not whether you carry the total hours worked as a Date/Time value or a Double.<BR><BR>The trick is in *displaying* the time and getting the right units.<BR><BR>You don&#039;t want to see that value as 8.25 hours; you want to see it as 08:15<BR><BR>And doing the display doesn&#039;t really depend on what format its stored in, does it?<BR><BR>See ASPFAQs, category "Date and Time".<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Actually, the best way...

...in my opinion, is "none of the above."<BR><BR>Keep the time in *MINUTES*. As an integer.<BR><BR>To do this, just multiply the hours by 60 and add the minutes, for each value you process.<BR><BR>Then to get the output answer:<BR><BR>&#060;%<BR>hrs = minuteCount 60 &#039; yes, that *is* a backslash!<BR>mins = minuteCount MOD 60<BR><BR>hrs = Right( "0" & hrs, 2 )<BR>mins = Right( "0" & mins, 2 )<BR>Response.Write hrs & ":" & mins<BR>%&#062;<BR><BR>Easier than working with hours and fractions of an hour. More accurate. No need to worry about rounding.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•