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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
patriotpacerAuthor Commented:
I need both sides dynamic.  I don't want to hard code anything.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
slightwv (䄆 Netminder) 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
patriotpacerAuthor Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.