View previous topic :: View next topic
|
Author |
Message |
santosh100678
New User
Joined: 21 Sep 2009 Posts: 55 Location: Kolkatta
|
|
|
|
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 |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hello Satish,
It should have return you -6. Btw what result you are expecting from the above query? |
|
Back to top |
|
|
santosh100678
New User
Joined: 21 Sep 2009 Posts: 55 Location: Kolkatta
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
|