Solved

Counting months between two dates

Posted on 2007-03-28
3
1,464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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