Article ID: 171097
Article Last Modified on 1/20/2007
Sub Date_MonthsBetweenDates()
Dim dBeginDate As Date
Dim dEndDate As Date
Dim intMonths As Integer
' Beginning date.
dBeginDate = DateValue("1/1/1993")
' Ending Date.
dEndDate = DateValue("2/1/1993")
' Calculate number of months between dates.
intMonths = ((Year(dEndDate) - Year(dBeginDate)) * 12) + _
Month(dEndDate) - Month(dBeginDate)
' Display number of months.
MsgBox Str$(intMonths) & " month(s)"
End Sub
NOTE: The number of months returned by this macro is not based on the exact
number of days between the two dates. For example, given a start date of
10/31/1993 and an end date of 11/2/1993, the macro returns one month.
173707 OFF97: How to Run Sample Code from Knowledge Base Articles
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon vb vba vbe
Keywords: kbdtacode kbhowto kbmacro kbmacroexample KB171097