Time Difference between two dates

G

Giberish

How do I calculate time between two different dates? I am entering on a
form a date that includes two different time entries.... StartTime and
EndTime.

For example I want to calculate a time difference if I have an entry on
12/28/06 with a [StartTime] of 22:45 that has an [EndTime] on the the
next day at 00:45. How can I calculate the difference if I only have
time entries that are not based on dates? Is there a way to calculate
the difference if the expression assumes that 22:45 is for today and
anything later ([EndTime]) is after that time carrying over into the
next day?
 
R

Rick Brandt

Giberish said:
How do I calculate time between two different dates? I am entering on
a form a date that includes two different time entries.... StartTime
and EndTime.

For example I want to calculate a time difference if I have an entry
on 12/28/06 with a [StartTime] of 22:45 that has an [EndTime] on the
the next day at 00:45. How can I calculate the difference if I only
have time entries that are not based on dates? Is there a way to
calculate the difference if the expression assumes that 22:45 is for
today and anything later ([EndTime]) is after that time carrying over
into the next day?

You would need an If-Then block (in code) or an IIf() function (no code) that
tests if EndTime is less than StartTime and add a day if it is. Then you can
use DateDiff on the result. You don't say what interval you want so here is an
example in minutes...

DateDiff("n", [StartTime], IIf([EndTime]<[StartTime], DateAdd("d", 1,
[EndTime]), [EndTime])
 
D

Douglas J. Steele

Rick Brandt said:
Giberish said:
How do I calculate time between two different dates? I am entering on
a form a date that includes two different time entries.... StartTime
and EndTime.

For example I want to calculate a time difference if I have an entry
on 12/28/06 with a [StartTime] of 22:45 that has an [EndTime] on the
the next day at 00:45. How can I calculate the difference if I only
have time entries that are not based on dates? Is there a way to
calculate the difference if the expression assumes that 22:45 is for
today and anything later ([EndTime]) is after that time carrying over
into the next day?

You would need an If-Then block (in code) or an IIf() function (no code)
that tests if EndTime is less than StartTime and add a day if it is. Then
you can use DateDiff on the result. You don't say what interval you want
so here is an example in minutes...

DateDiff("n", [StartTime], IIf([EndTime]<[StartTime], DateAdd("d", 1,
[EndTime]), [EndTime])

Or look at http://www.mvps.org/access/datetime/date0008.htm at "The Access
Web"
 
G

Giberish

Thanks Rick... That formula works exactly the way I want it to.
Thanks...!!!


Rick said:
Giberish said:
How do I calculate time between two different dates? I am entering on
a form a date that includes two different time entries.... StartTime
and EndTime.

For example I want to calculate a time difference if I have an entry
on 12/28/06 with a [StartTime] of 22:45 that has an [EndTime] on the
the next day at 00:45. How can I calculate the difference if I only
have time entries that are not based on dates? Is there a way to
calculate the difference if the expression assumes that 22:45 is for
today and anything later ([EndTime]) is after that time carrying over
into the next day?

You would need an If-Then block (in code) or an IIf() function (no code) that
tests if EndTime is less than StartTime and add a day if it is. Then you can
use DateDiff on the result. You don't say what interval you want so here is an
example in minutes...

DateDiff("n", [StartTime], IIf([EndTime]<[StartTime], DateAdd("d", 1,
[EndTime]), [EndTime])
 

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