Oracle - Dates YTD

Have a query that I want to always run for the first day of the year and have an ending date as of the previous day.

How do I adjust the part below to have it always/dynamically start at the beginning of the year and have the ending date be yesterday?

AND TRUNC(s.transaction_date) >= TO_DATE('1/1/2013','mm/dd/yyyy')
AND TRUNC(s.transaction_date) <= TO_DATE('09/16/2013','mm/dd/yyyy')

Open in new window

Who is Participating?
slightwv (䄆 Netminder)Connect With a Mentor Commented:
Putting it all together:
AND s.transaction_date >= trunc(sysdate,'YYYY')
AND s.transaction_date < trunc(sysdate)

I removed the TRUNC on your calls because they aren't necessary and will ignore any possible indexes you may have.
slightwv (䄆 Netminder) Commented:
Beginning of year:

slightwv (䄆 Netminder) Commented:
that said, based on your query, just change the second part to:
AND TRUNC(s.transaction_date) < trunc(sysdate)

Instead of <=

trunc without a format sets the time portion to 0.  So "< trunc(sysdate)" means less than today at 0-hundred hours.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

patriotpacerAuthor Commented:
I need both sides dynamic.  I don't want to hard code anything.
slightwv (䄆 Netminder) Commented:
>>I need both sides dynamic.  I don't want to hard code anything.

I didn't hard-code anything.  I used the sysdate function which returns the system's date/time.
patriotpacerAuthor Commented:
Sorry I didn't see your first comment.  

let me try
patriotpacerAuthor Commented:
Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.