Solved

Counting months between two dates

Posted on 2007-03-28
3
1,459 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

895 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

17 Experts available now in Live!

Get 1:1 Help Now