Adding times in Access

M

mike

I need to caculate the hours worked from two columns. in column 1 I have an
8:am start time and column b has a 17:00 finish time. I could also have a
start time of 20:00 and finish time of 5:00. The answer need to be in hours
and minutes please.
 
D

Danny J. Lesandrini

Someone may have an off-the-shelf solution for you, but it's clear to me that
you're going to have to plan for 2 scenarios:

1) The two times are in the same day
2) The hour crosses midnight

Air code like this ...

If Time2 < Time1 Then
' Add Time to Midnight to Time1
Result = (1440 - DateDiff("n", #00:00#, Time2)) + DateDiff("n", #00:00#, Time1)
Else
' take diff of two times
Result = DateDiff("n", Time1, Time2)
End If

This will give you the minutes, which you can to convert to hours / minutes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top