DateDiff question...

Dave Eyley

Registered User.
Local time
Today, 08:34
Joined
Sep 5, 2002
Messages
254
Using Date1 and Date2 as user inputs I use DateDiff() to give me the months difference...

Me!TM=DateDiff("m",Date1,Date2)

But the results are not quite what I expect...
If I enter Date1 as 01/08/2004 (dd/mm/yyyy)
and enter Date2 as 31/07/2005 (dd/mm/yyyy)

I get a count of 11 months, not 12 as expected.

But then if I enter Date 1 As 01/08/2004
and enter Date 2 as 28/02/2005

I get a count of 6 months as I would expect...

So, I thought, add a day to date2 to compensate...

Doing that gives me 12 months for the year count but 7 months for the 6 month count!!!

Any suggestions? Give up Access, perhaps?

Dave Eyley
 
Last edited:
DateDiff starts counting (in this case) the month after the first date. So August to Feb = 6 and August to July = 11.

If you want an inclusive count add +1 after the datediff

Code:
 DateDiff("m",[date1],[date2])+1

Col
 
Thanks Col,

I'm afraid it was me...locked into the idea that August to February was 6 months and not 7 as calculated by DateDiff.

Dave Eyley
 

Users who are viewing this thread

Back
Top Bottom