A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Time Difference between two dates



 
 
Thread Tools Display Modes
  #1  
Old December 28th, 2006, 08:36 PM posted to microsoft.public.access.forms
Giberish
external usenet poster
 
Posts: 8
Default Time Difference between two dates

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?

  #2  
Old December 28th, 2006, 09:04 PM posted to microsoft.public.access.forms
Rick Brandt
external usenet poster
 
Posts: 4,354
Default Time Difference between two dates

Giberish wrote:
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])

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


  #3  
Old December 28th, 2006, 09:14 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Time Difference between two dates

"Rick Brandt" wrote in message
t...
Giberish wrote:
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"

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)



  #4  
Old December 28th, 2006, 09:24 PM posted to microsoft.public.access.forms
Giberish
external usenet poster
 
Posts: 8
Default Time Difference between two dates

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


Rick Brandt wrote:
Giberish wrote:
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])

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.