View previous topic :: View next topic
|
Author |
Message |
balaji81_k
Active User
Joined: 29 Jun 2005 Posts: 155
|
|
|
|
Hi ,
I have to insert two date fields(EFFECTIVE & EXPIRATION DATE) in a table in which effective date will be current date and expiration is of 2 yrs exactly from that date . I know we can do in SELECT SQL statement by number of days adding to current date but if in between if leap year falls then we need to have 1 more day extra . I can check for successive years for leap year check thru COBOL but is there anything i can handle in SQL query itself
can any one guide me .
[/code]
Code: |
SELECT CURRENT_DATE + 730 or 731 DAYS
FROM TEST_TABLE
WITH UR ; |
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
Is that what you want?
Code: |
select current date + 2 years from sysibm.sysdummy1 |
|
|
Back to top |
|
|
balaji81_k
Active User
Joined: 29 Jun 2005 Posts: 155
|
|
|
|
Yes, I need the same . I believe it calculate from system date which in turns handle leap year days too . |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
yes,
Code: |
select
CASE (mod(year(current date), 400)) WHEN 0 THEN 366
ELSE
CASE (mod(year(current date), 4)) WHEN 0 THEN
CASE (mod(year(current date), 100)) WHEN 0 THEN
365 ELSE 366 END
ELSE 365 END
end
end
from sysibm.sysdummy1 |
This should give you days and handle leap year and can be used in your original post if you don't want above. |
|
Back to top |
|
|
|