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

Calculating hours and minutes between two times in HH:MM format

Status
Not open for further replies.

andielangley

Programmer
Feb 11, 2003
17
GB
I have a table of flexitime data which contains four fields AM Time In, AM Time Out, PM Time In and PM Time Out. All the fields are of type Date/Time and are formatted as Short Date so they appear as 08:45, 13:56, etc

What I need to do with a query is find out the number of hours and minutes worked between those times and display the final result in the format HH:MM. So, for example, the check in and out values are 08:30, 12:30, 13:30, 17:00 and the result I need is 07:30 representing 7 and a half hours worked.

I can do the arithmetic in a calculated field but the result is displayed as a numeric fraction and I have no idea how to get this into the format I need.

Any advice would be appreciated, thanks
 
I have a query similar to that..I also have 2 fields in short date format(STARTTIME and ENDTIME), I need to know whether the current time is within the range.

please help.

Sincerely,

Ashm01
 
A correction to my original post - the fields are in Short Time format, not Short Date as I originally stated. I don't know if that makes any difference...
 

Hi,
Check this
thread702-569949
multiply the result by 60 wil the time in minutes

May be useful
In
ZmrAbdulla
 
Say your expression are like this
Expr1:[AM Time Out] - [AM Time In]
Expr2:[PM Time Out] - [PM Time In]

And the results are
0.166666666666667
0.145833333333333

This expression in another column will give you
7:30

Expr3: Int(([Expr1]+[Expr2])*24) & ":" & Int((([Expr1]+[Expr2])*24-Int(([Expr1]+[Expr2])*24))*60)

There may be an easier way to do this but the Format function didn't seem to do it so I worked it out long hand.

Paul

 
Thanks, this was helpful, but I find that Expr3 is sometimes a minute short - possibly to do with rounding errors of the INT function? I'm getting closer to a working solution though.
 
Can you give me a couple of examples that have rounding problems? I will look at it a little more.

Paul
 
You can try this instead. It seems to pick up that extra minute.

Expr4: Int(((([Expr1]+[Expr2])*24)*60)/60) & ":" & (([Expr1]+[Expr2])*24)*60 Mod 60


Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top