I might be reading too much into your post, but the fact that you raise the
question of it being unable to sum above 24 hours makes me wonder whether you
are using a date/time data type as a basis for the HoursWorked? The
date/time data type stores values representing a point in time not durations
of time. The values are actually stored as a 64 bit floating point number as
an offset from 31 December 1899 00:00:00.
Time sheet applications usually record the start and end times of each
continuous work period, e.g. day or half-day. If you subtract the start time
from the end time you get a value which when formatted as a time does in fact
show the time duration, but only if less than 24 hours. Above that the
result formatted as a time would be the time less 24 hours (or multiples of
24 if the duration spans several days). If the individual differences are
each less than 24 hours, summing them and formatting the result as time will
again only give the result less 24 hours or multiples thereof.
There are a number of ways around this. You could for instance return the
difference in minutes between each start and end time using the DateDiff
function and then convert this into hours, e.g. 7 hours 30 minutes would be
represented as 7.5. These values can then easily be summed to give the total
hours worked per week.
Another way is to do the whole calculation on the basis of the underlying
values and convert that to a string showing the hours and minutes. The
following function does this:
Public Function TimeElapsed(dblTotalTime As Double) As String
Const HOURSINDAY = 24
Dim lngHours As Long
Dim strMinutesSeconds As String
'get number of hours
lngHours = Int(dblTotalTime) * HOURSINDAY + _
Format(dblTotalTime, "h")
' get minutes and seconds
strMinutesSeconds = Format(dblTotalTime, ":nn:ss")
TimeElapsed = lngHours & strMinutesSeconds
End Function
In query for instance you could have a computed column which calls the
function:
TotalHours: TimeElapsed(Sum([EndTime] – [StartTime]))
or you could do similarly with a computed control on a form.
Ken Sheridan
Stafford, England
Northern said:
I have a form that gives the total hours worked each day, I would like to add
all these up to give a weekly total hours it of course only displays up
24hrs, how do I display the total if it goes over 24 hours for the week