Using MS Access/MS access - DateDiff function
I am trying to create a query/form where I can plug in two different dates and get the year, month, and days to populate into their own individual fields. I have been able to get the year and month to display accurately, but I have no idea how to get the days to account for the different number of days depending on the month. Here is what I have so far:
Field1 - Start Date
Field2 - End Date
Field3 - Years: DateDiff("yyyy",[Start Date],[End Date])
Field4 - Months: DateDiff("m",[Start Date],[End Date])-([years]*12)-1
Field5 - Days: DateDiff("d",[Start Date],[End Date])-([Years]*365)-([Months]*30)
First question is what do you plan on doing with the information.
From what you want I would think this is a better option for a form. So you have a form with 5 textbox controls:
txtStart: Start Date
txtEnd: End Date
The idea is that you adjust the start date for each DateDiff). You were close, but I think this will work better.
Hope this helps,
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA