Solved

Counting months between two dates

Posted on 2007-03-28
3
1,458 Views
Last Modified: 2008-01-09
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


0
Comment
Question by:mitchell255
3 Comments
 
LVL 10

Accepted Solution

by:
ksaul earned 500 total points
ID: 18809687
MonthsCalc: Month([EndDate])-IIf(Day([DriversEffective])<16,Month([DriversEffective]),Month([DriversEffective])+1)
0
 
LVL 39

Expert Comment

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

Steve
0
 
LVL 9

Expert Comment

by:samopal
ID: 18809804
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)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now