IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

when we subtract two date then require current month number


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
santosh100678

New User


Joined: 21 Sep 2009
Posts: 55
Location: Kolkatta

PostPosted: Wed Mar 17, 2010 6:34 pm
Reply with quote

Hi ,

I have a query regarding subtraction of two month

SELECT MONTH(DATE(('2009-07-31'))- DATE(('2010-02-28')))
FROM SYSIBM.SYSDUMMY1;
if i put this its work for all 11 month but for feb its shows wrong
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Wed Mar 17, 2010 6:38 pm
Reply with quote

Hello Satish,

It should have return you -6. Btw what result you are expecting from the above query?
Back to top
View user's profile Send private message
santosh100678

New User


Joined: 21 Sep 2009
Posts: 55
Location: Kolkatta

PostPosted: Wed Mar 17, 2010 8:44 pm
Reply with quote

if you count these month then month must 7 month

08-31
09-30
10-31
11-30
12-31
01-31
02-32
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 17, 2010 8:57 pm
Reply with quote

Hello,

Quote:
if you count these month then month must 7 month
You are counting "your way" which is not the same as DB2. . . You need to change your expectation.

If you use 2010-03-01 you will get -7. . .
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Mar 18, 2010 1:20 pm
Reply with quote

The value returned is an approximation
because it does not account for leap years and assumes only 30 days per month.

How is month difference supposed to work (according to you)?

Is 28/feb and 01/mar = 1 month ?
Is 28/feb and 28/mar = 1 month ?
Is 28/feb and 29/mar = 1 month ?
Is 28/feb and 30/mar = 1 month ?
Is 28/feb and 31/mar = 1 month ?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
Search our Forums:

Back to Top