Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Leap Year Handling

568144Mar 21 2007 — edited Mar 21 2007
Hi All,

I just want to get the exactly one year previous date by using the below query: for the leap year...

update day
SET FLAG = 'Y'
WHERE PERIOD_DATE BETWEEN TRUNC(ADD_MONTHS(TO_DATE(20050228,'YYYYMMDD'),-12),'MON') and
ADD_MONTHS(TO_DATE(20050228,'YYYYMMDD'),-12)

In the same time while we use the same query for the leap year date:

select * from day
WHERE PERIOD_DATE BETWEEN TRUNC(ADD_MONTHS(TO_DATE(20080229,'YYYYMMDD'),-12),'MON')
AND TO_DATE(20080229,'YYYYMMDD') + NUMTOYMINTERVAL(-1,'YEAR')

I receive the following error - ORA-01839: date not valid for month specified.
Problem:FLAG was incorrectly set to 'Y' for Feb 29 in 2004 during the report processing of Feb 28 data. Because of this, the extra day of Feb 29 2004 of Sales data was incorrectly being added to a report, thus overstating MTD sales of Feb 28 2004 by one full day. This appears to be caused by the fact that there were 28 days in Feb 2005 and 29 days in Feb 2004 becuase of the leap year. This will not cause problems until the next leap year.

Can you please give me the resolution of the above.

Thanks & Regards,
Satheesh

Message was edited by:
user565141

Message was edited by:
user565141
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2007
Added on Mar 21 2007
19 comments
4,321 views