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!

Year to date report - how do I get dates without hard coding a year?

957056Aug 21 2012 — edited Aug 22 2012
I am writing a monthly report that will run for example on Sept1 but want to extract data for Jan 1, 2012 thru Aug 31, 2012. But also need to consider when I run report on Jan 1, 2013 for all of 2012. I know I could use the add_months(sysdate,-1) to get previous month but then will still have issues running on Jan 2013 for the year.

SELECT data
FROM tables
WHERE data_date between start-date (which would be Jan 1, 2012 but also when I run on Jan 1 2013 for previous year)
and last_day(add_months(sysdate, -1)

Thanks in advance

Jackie
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2012
Added on Aug 21 2012
5 comments
640 views