Time differences

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to get the differences between two times in Access 2003.

I tried using Format([StartTime] -1 -[EndTime], "Short Time") which I got
from the MVP website. However, when I use it for the following times:

Begin Time: 08/29/2006 6:26:00 AM
End Time: 08/29/2006 6:26:00 AM

The result is: 12:00:00 AM when it should be 00:00:00.

If I use:

Begin Time: 08/29/2006 6:33:54 AM
End Time: 8/29/2006 7:00:00 AM

The result is: 12:26:00 AM when it should be 00:26:00.

Any help would be appreciated.
 
hi,
I'm trying to get the differences between two times in Access 2003.

I tried using Format([StartTime] -1 -[EndTime], "Short Time") which I got
[EndTime]-[StartTime] makes more sense, but why are you not using the
DateDiff() function?


mfG
--> stefan <--
 
You are wanting a quantity of time, not a point in time. The Date/Time data
type represents a point in time, not a quantity. To do math with dates, you
need to use date functions. In this case, you would want to use the DateDiff
function which returns a number of intervals of the portion of the date you
want. I would recommend you look in VBA Help at the Date Diff function.
If you want to present the quantity of time in Hours and Minutes, you will
find the \ operator and Mod operators very useful. For example, lets same
the DateDiff function returns 75 mintes.

dtmStart = "08/29/2006 8:00:00 AM"
dtmEnd = "08/29/2006 9:15:00 AM"

lngElapsedTime = DateDiff("n", dtmStart, dtmEnd)

strTime = Format(lngElapsedTime\60, "00:") & format( lngElapsedTime mod 60,
"00")

strTime will be

01:15
 
Thank you so much. That was exactly what I was looking for.
--
M. Shipp


Klatuu said:
You are wanting a quantity of time, not a point in time. The Date/Time data
type represents a point in time, not a quantity. To do math with dates, you
need to use date functions. In this case, you would want to use the DateDiff
function which returns a number of intervals of the portion of the date you
want. I would recommend you look in VBA Help at the Date Diff function.
If you want to present the quantity of time in Hours and Minutes, you will
find the \ operator and Mod operators very useful. For example, lets same
the DateDiff function returns 75 mintes.

dtmStart = "08/29/2006 8:00:00 AM"
dtmEnd = "08/29/2006 9:15:00 AM"

lngElapsedTime = DateDiff("n", dtmStart, dtmEnd)

strTime = Format(lngElapsedTime\60, "00:") & format( lngElapsedTime mod 60,
"00")

strTime will be

01:15


SHIPP said:
I'm trying to get the differences between two times in Access 2003.

I tried using Format([StartTime] -1 -[EndTime], "Short Time") which I got
from the MVP website. However, when I use it for the following times:

Begin Time: 08/29/2006 6:26:00 AM
End Time: 08/29/2006 6:26:00 AM

The result is: 12:00:00 AM when it should be 00:00:00.

If I use:

Begin Time: 08/29/2006 6:33:54 AM
End Time: 8/29/2006 7:00:00 AM

The result is: 12:26:00 AM when it should be 00:26:00.

Any help would be appreciated.
 

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

Back
Top