Skip to Main Content

Analytics Software

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!

get the previous date in oracle sql

user12251389Feb 21 2022 — edited Feb 21 2022

I have below query which gives current date. I want to return the value as String for this reason i used TO_CHAR.
select NVL(TO_CHAR(sysdate,'DD.MM.YYYY'),0) from dual
But i need to modify the logic such that it should always give the date from the yesterday.
This logic is very simple when the query runs from every Tuesday till Friday. I just need to use below query for this:
select NVL(TO_CHAR(sysdate - 1,'DD.MM.YYYY'),0) from dual
But there is exception. When the query runs on every Monday it should give the date from last Friday. And i dont know how i can achieve all this logic in the same query.
For example when the query runs today it should return the date from last Friday i.e 18.02.2022. When the query runs tommorow it should return the date from Today 21.02.2022.
I want to avoid dates from every Saturday and Sunday.

Comments