473,508 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

month between 2 dates

I need to print the number of months between 2 dates. The best (easy)
solution I could come up with was the approximation int( (days(end_date)
- days(begin_date) / (365.24/12)) which is accurate enough for most
uses, but I wondered if there were a "monthsdiff( date1, date2)"
somewhere in the documentation I haven't found, probably by another name?
Nov 12 '05 #1
5 12397
Have you considered:
months_between = year(end)*12+month(end) - (year(start)*12+month(start))

Bob Stearns wrote:
I need to print the number of months between 2 dates. The best (easy)
solution I could come up with was the approximation int( (days(end_date)
- days(begin_date) / (365.24/12)) which is accurate enough for most
uses, but I wondered if there were a "monthsdiff( date1, date2)"
somewhere in the documentation I haven't found, probably by another name?

Nov 12 '05 #2
Phil Sherman wrote:
Have you considered:
months_between = year(end)*12+month(end) - (year(start)*12+month(start))

Bob Stearns wrote:
I need to print the number of months between 2 dates. The best (easy)
solution I could come up with was the approximation int(
(days(end_date) - days(begin_date) / (365.24/12)) which is accurate
enough for most uses, but I wondered if there were a "monthsdiff(
date1, date2)" somewhere in the documentation I haven't found,
probably by another name?

I had not; probably a senior moment :-). Thank you.
Nov 12 '05 #3
Do the days matter?

MONTH(End_Date) - MONTH(Begin_Date)

B.

Nov 12 '05 #4
This doesn't work when the dates span years.

Phil Sherman

Brian Tkatch wrote:
Do the days matter?

MONTH(End_Date) - MONTH(Begin_Date)

B.

Nov 12 '05 #5
Phil Sherman wrote:
This doesn't work when the dates span years.

Phil Sherman

Brian Tkatch wrote:
Do the days matter?

MONTH(End_Date) - MONTH(Begin_Date)

B.

(12 * YEAR(end_date) + MONTH(end_date))
- (12 * YEAR(begin_date) + MONTH(begin_date))

Something like that (untested....)

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3574
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not...
6
77795
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From...
18
6612
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a...
0
1888
by: larry | last post by:
I am in the process of rewriting one of my first PHP scripts, an event calendar, and wanted to share the code that is the core of the new calendar. My current/previous calendar processed data...
22
31147
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
4
39298
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
2
3311
by: jai80 | last post by:
hi frenz, I want to display all the dates and day of the given year and month. For ex; if i choose 2007 and select the month January, i want to generate all the dates for this selection ...
5
10395
by: soni2926 | last post by:
Hi, I have a web application, asp.net and c# done in 2.0, which is going to return rows from the db with dates or certain events. The db is going to have events dates for the entire year, but on...
2
5832
by: ncsthbell | last post by:
I am having problems getting the end date to calculate correctly. I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
2
1797
by: metaperl | last post by:
First a simple question: Is it allowed to provide a date range that has an illegal date. For instance SELECT * FROM tbl WHERE datex >= 2007-09-01 AND datex <= 2007-09-31 Now for my real...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.