Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Get the difference in months between two dates

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
sanil m

New User


Joined: 24 Aug 2007
Posts: 38
Location: chennai

PostPosted: Fri Feb 29, 2008 2:19 pm    Post subject: Get the difference in months between two dates
Reply with quote

Hi,

I want to get the difference in months between two dates,

i tried the query,

Code:
SELECT MONTH(DATE('2008-03-01') - DATE('2007-02-01'))
       FROM SYSIBM.SYSDUMMY1;     


i am getting the answer as 1,

but i want it as 13.

please help me with this.
Back to top
View user's profile Send private message

ksk

Active User


Joined: 08 Jun 2006
Posts: 356
Location: New York

PostPosted: Fri Feb 29, 2008 4:57 pm    Post subject:
Reply with quote

you are extracting month and subtracting, so it is giving 1.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Feb 29, 2008 6:29 pm    Post subject: Re: Get the difference in months between two dates
Reply with quote

sanil m wrote:
Hi,

I want to get the difference in months between two dates,

i tried the query,

Code:
SELECT MONTH(DATE('2008-03-01') - DATE('2007-02-01'))
       FROM SYSIBM.SYSDUMMY1;     


i am getting the answer as 1,

but i want it as 13.

please help me with this.


Code:
select MONTH(DATE('2008-03-01') - DATE('2007-02-01')) + (YEAR(DATE('2008-03-01') - DATE('2007-02-01')) * 12) FROM SYSIBM.SYSDUMMY1;   



But you still have the left over days which could be as high as 31.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Fri Feb 29, 2008 6:33 pm    Post subject: Reply to: Get the difference in months between two dates
Reply with quote

Quote:
But you still have the left over days which could be as high as 31.


Hi Craq,

sometimes I am boring to death ,
but it seems almost impossible to stick into people heads
that date calculations are not something that can be solved by a forum answers
but it is something that must be defined at company levels standards
and supported by the IT infrastructure with a proper set of general use subroutines/functions
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Feb 29, 2008 7:14 pm    Post subject:
Reply with quote

I was on a project that involved a lot of date calculations and when we asked about date differences we got more answer then we could handle, some said todays-date - todays-date = 0, some said 1 and some said it depends. Todays-date - yesterdays-date = 1 (even from the people who said 1 for todays-date - todays-date) and some said that if the month was different then it was 2. We finally had to by pass the managers and go to the agency head.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Feb 29, 2008 11:20 pm    Post subject:
Reply with quote

Craq Giegerich wrote:
(even from the people who said 1 for todays-date - todays-date)
..and I was thining that I'm the only 'dumb' left in this world... icon_smile.gif
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Feb 29, 2008 11:22 pm    Post subject:
Reply with quote

Anuj D. wrote:
..and I was thining that I'm the only 'dumb' left in this world... icon_smile.gif


If it wasn't for the dumb ones the rest of us would be out of work.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Difference between TWALENG and TWASIZE Arunkumar Chandrasekaran CICS 3 Tue Jan 03, 2017 12:57 pm
No new posts Sticky: difference between ... DUMMY ... and ... enrico-sorichetti JCL & VSAM 0 Mon Oct 17, 2016 4:31 pm
No new posts Difference space showed for TS and it... autobox DB2 1 Thu Apr 14, 2016 1:07 pm
No new posts Difference Between CICS WebSupport an... sachinji84 CICS 1 Mon Mar 07, 2016 7:25 pm
No new posts Difference between -180 and -181 with... deepak_shrivastava DB2 4 Wed Jan 06, 2016 10:00 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us