By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,514 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,514 IT Pros & Developers. It's quick & easy.

month between 2 dates

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
Do the days matter?

MONTH(End_Date) - MONTH(Begin_Date)

B.

Nov 12 '05 #4

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.