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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|