View previous topic :: View next topic
|
Author |
Message |
prasanthi mathireddi
New User
Joined: 19 Jun 2008 Posts: 2 Location: chennai
|
|
|
|
Hi,
I need to find out the difference between two dates(YYYY-MM-DD) in cobol-db2 program.
Output should also needed in Date format(YYYY-MM-DD).
EX: If input dates are 2008-06-20 and 2005-05-01 which i am getting it from query , i need to find out the difference between two dates as 0001-01-19.
Thanks,
Prasaha |
|
Back to top |
|
|
Suresh Ponnusamy
Active User
Joined: 22 Feb 2008 Posts: 107 Location: New York
|
|
|
|
How the difference between 2008-06-20 and 2005-05-01 will be
0001-01-19?
How did arrive this result?
To find out the difference use the below query.
SELECT DATE(DATE('2008-06-20') - DATE('2005-05-01'))
FROM SYSIBM.SYSDUMMY1;;
I don't understand what you are going to achieve with this (Difference between 2 dates in date format). |
|
Back to top |
|
|
ascelepius
New User
Joined: 16 Jun 2008 Posts: 35 Location: bangalore
|
|
|
|
Well as Suresh has pointed out, the result 0001-01-19 from the difference between 2008-06-20 and 2005-05-01 seems illogical.
As far finding the difference between 2 dates(as an integer) go, the std SQL would be,
Code: |
SELECT DAYS('2008-06-20') - DAYS('2005-05-01')
FROM SYSIBM.SYSDUMMY1; |
But you need to be sure what you need!
regards,
asci(i) |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
Back to top |
|
|
prasanthi mathireddi
New User
Joined: 19 Jun 2008 Posts: 2 Location: chennai
|
|
|
|
Thanks Suresh. Your query worked well but with little modifiation. i changed the query as below.
SELECT CHAR(DATE('2008-06-20') - DATE('2005-05-01'))
INTO :WS-OUT-DATE
FROM SYSIBM.SYSDUMMY1;
I got result WS-OUT-DATE as 00030119
Later i manipulated WS-OUT-DATE to reqired date format.
When i tried the below query
SELECT DATE(DATE('2008-06-20') - DATE('2005-05-01'))
FROM SYSIBM.SYSDUMMY1;
i didn't get correct result.
Thanks a lot for all who have gave reply for my post. |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
Quote: |
SELECT DATE(DATE('2008-06-20') - DATE('2005-05-01'))
FROM SYSIBM.SYSDUMMY1; |
What result did you get when you executed this query?
What is the declaration of the variable : WS-OUT-DATE? |
|
Back to top |
|
|
|