449,386 Members | 1,747 Online
Need help? Post your question and get tips & solutions from a community of 449,386 IT Pros & Developers. It's quick & easy.

# # of Months Calcuation only returns 0

 P: n/a I'm trying to create a function that calculates the number of months between two dates. DateDiff won't work because I need to add one month if the day of the end_date is greater than the day of the start_date. I can't determine where the problem is in the code below. It returns 0 everytime. Any input is welcomed. ************************************ Public Function CalculateMonths(ipdtStart As Date, ipdtEnd As Date) As Integer Dim intNumberOfMonths As Integer Dim intStartMonth As Integer Dim intEndMonth As Integer Dim intYears As Integer intStartMonth = Month(Start_Date) intEndMonth = Month(End_Date) intYears = Year(End_Date) - Year(Start_Date) If Day(ipdtStart) >= Day(ipdtEnd) Then intNumberOfMonths = (intEndMonth - intStartMonth) Else intNumberOfMonths = (intEndMonth - intStartMonth) + 1 End If CalculateMonths = intNumberOfMonths + (12 * intYears) End Function Nov 13 '05 #1