Link to home
Start Free TrialLog in
Avatar of mitchell255
mitchell255Flag for United States of America

asked on

Counting months between two dates

MS Access 2003 QUERY
Help!  I need to calculate the number of months due based on the following criteria:

[Efective] = If [DriversEffective] datepart is prior to the 16th of any given month the count that month as the first month, otherwise begin month count the following month.

[EndDate] = If [DriversTermed] is null then [EndDate] = 1st of next month, otherwise, [EndDate] = [DriversTermed]

[EndDate] minus [Effective]  (in number of months)

I need this in SQL so I can put it into a query.  Any help is appreciated


ASKER CERTIFIED SOLUTION
Avatar of ksaul
ksaul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stevbe
stevbe

DateDiff("m", NZ([DriversTermed], CDate("1/" & Month(Date) & "/" & Year(Date))),
IIF(Day([DriversEffective]) > 1, DateAdd("m", 1, [DriversEffective]), [DriversEffective]))

Steve
SELECT  DateAdd("m",IIf(Day(dat1)<16,0,1),DateSerial(Year(dat1),Month(dat1),1)) as d1, nz(dat2,dateadd("m",1,d1)) as d2, datediff("m",d1,d2)