INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Microsoft: Access Forms FAQ

## How to

 How can I find the days/months/years between two dates by Rolliee faq702-3928 Posted: 23 Jul 03 Write a global function as shown below: The return value is Years: ??  Months: ?? Days: ?? with the prober values instead of '??'This handles leap years by using the built in functions of VB.Public Function DateDiff2(ByVal d1 As Date, ByVal d2 As Date) As StringDim d3 As Date, nDays As IntegerDim d1Day As Integer, nDayStart As IntegerDim nYears As Integer, d1Mon As Integer, MonLast As Integer, nn As Integer, nMon As Integer, d1Year As Integer    If d1 > d2 Then      d3 = d1      d1 = d2      d2 = d3    End If    d1Day = Day(d1)    d1Mon = Month(d1)    d1Year = Year(d1)    nn = 0    nMon = 0    nDays = 0    nYears = 0      MonLast = d1Mon    Do While d2 > d1       d1 = d1 + 1       nn = nn + 1       nDays = nDays + 1              If (Day(d1) = d1Day) And Month(d1) <> MonLast Then         nMon = nMon + 1         nDays = 0         MonLast = Month(d1)         If nMon = 12 Then           nMon = 0           nYears = nYears + 1         End If       End If    Loop    DateDiff2 = "Years: " & Format(nYears, "00") & "   Months: " & Format(nMon, "00") & "   Days: " & Format(nDays, "00")End Function Back to Microsoft: Access Forms FAQ Index Back to Microsoft: Access Forms Forum

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!