?
Solved

Counting months between two dates

Posted on 2007-03-28
3
Medium Priority
?
1,470 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 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

862 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