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

Time Calculation - Hours

Status
Not open for further replies.

nike2000

Technical User
Apr 1, 2003
61
GB
Hi,
I have a form that I am trying to calculate time taken to do certain tasks.

The fields I have are StartTime and EndTime.
I have used:

=Sum([StartTime]-[EndTime])

but anything over 24 hours reverts to 01:30 for example.

I would like to calculate the number of hours over 24 without taking into account days. SO for example I would like to be able to return values like 28 hours or 36 hours.

Can I have some advice please?
Thanks in advance,
Miguel

 
I'm not working on my Access PC so can't give you the precise syntax, but try the DateDiff function and ask for hours - the problem you have is that MS try and be helpful (and often they are, but sometimes their help can be confusing) and have time variables use 'time' maths for simple add etc. So you have to be careful and work out what you want. (By time maths I mean Hours use MOD 24, minutes MOD 60 etc).

.
 
This is from Microfoft.com article 210276 for Access 2000

Hope it helps

To calculate and format time intervals correctly, follow these steps:
Create a module and type the following line in the Declarations section if it is not already there:Option Explicit

Type the following procedure:'------------------------------------------------------------------
' This function calculates the elapsed time between two values and
' formats the result in four different ways.
'
' The function accepts interval arguments such as the following:
'
' #5/12/95 6:00:00AM# - #5/11/95 10:00:00PM#
'
' -or-
'
' [End Time]-[Start Time]
'------------------------------------------------------------------

Function ElapsedTime (Interval)
Dim x
x = Int(CSng(Interval * 24 * 3600)) & " Seconds"
Debug.Print x
x = Int(CSng(Interval * 24 * 60)) & ":" & Format(Interval, "ss") _
& " Minutes:Seconds"
Debug.Print x
x = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn:ss") _
& " Hours:Minutes:Seconds"
Debug.Print x
x = Int(CSng(Interval)) & " days " & Format(Interval, "hh") _
& " Hours " & Format(Interval, "nn") & " Minutes " & _
Format(Interval, "ss") & " Seconds"
Debug.Print x

End Function

Type the following line in the Immediate window, and then press ENTER:
? ElapsedTime(#6/1/1999 8:23:00PM#-#6/1/1999 8:12:12AM#)

Note that the following values are displayed:
43848 Seconds
730:48 Minutes:Seconds
12:10:48 Hours:Minutes:Seconds
0 days 12 Hours 10 Minutes 48 Seconds


Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top