Count the number of Months Between two dates (1 Viewer)

David Bailey

New member
Local time
Today, 20:31
Joined
Sep 10, 2002
Messages
5
Hello

Does anybody know a formula that will enable me to count the number of months between two dates.

I am sure it must be very easy, but the help menu is no help.

Thanks
 

yellow

Registered User.
Local time
Today, 20:31
Joined
May 16, 2002
Messages
122
Datediff("m",FirstDate,SecondDate)

The "m" means you want to know thenumber of months between the two dates. Others are:

yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
 

David Bailey

New member
Local time
Today, 20:31
Joined
Sep 10, 2002
Messages
5
Count of Months - Thanks

Thanks, works brilliantly
 

sherimartin

New member
Local time
Today, 12:31
Joined
Sep 9, 2013
Messages
6
I am trying t implement the code to find the months between two dates in Access. However I keep getting an error "Expected End Sub" although its in the code. Can someone help?
This is the code below:
Private Sub WC_Visit1_Date_Exit(Cancel As Integer)
Public Function MydateDiff(Interval, DOB, WC_Visit1_Date)
Dim months, d1, d2
If IsNull(DOB) Or IsNull(WC_Visit1_Date) Then
MydateDiff = Null
Exit Function
End Sub
End If


If DOB < WC_Visit1_Date Then
d1 = DOB
d2 = WC_Visit1_Date
Else
d1 = WC_Visit2_Date
d2 = DOB
End If

months = DateDiff("m", d1, d2)

If months > 15 Then
MsgBox ("Patient is Older than 15 Months")
Else
If months <= 15 Then
MsgBox ("Patient is Eligible, Please Enter Date")
Me.WC_Visit1_Date.SetFocus
End If
End If
End Function
 

yellow

Registered User.
Local time
Today, 20:31
Joined
May 16, 2002
Messages
122
Nothing like replying to a thread that is 12 years old right :)

You don't have an End Sub.

You have a function in a sub. They need to be separate. So...

Private Sub WC_Visit1_Date_Exit(Cancel As Integer)
Code
End Sub

Public Function MydateDiff(Interval, DOB, WC_Visit1_Date)
Code
End Function
 

Users who are viewing this thread

Top Bottom