• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 69
  • Last Modified:

How to get previous week friday based on sysdate.

How to get previous week friday based on sysdate.  We are planning to include this logic on a job that runs daily.

Please advise !
1 Solution
slightwv (䄆 Netminder) Commented:
Try this:
select next_day(sysdate-7,'FRIDAY') from dual;
johnsoneSenior Oracle DBACommented:
If the current day is Friday, what do you want returned.  Let's say that today is 10/07/2016.  Should it return 10/07/2016 or 09/30/2016?

If the current day is a Friday, sysdate-7 will return today, not last Friday.  If you truly want last Friday, you have to do sysdate-8.

This will show the difference between minus 7 and minus 8:
     AS (SELECT To_date('10022016', 'mmddyyyy') + LEVEL - 1 dt 
         FROM   dual 
         CONNECT BY LEVEL < 8) 
       Next_day(dt - 7, 'FRIDAY') minus7, 
       Next_day(dt - 8, 'FRIDAY') minus8 
FROM   x; 

Open in new window

Notice that the difference is on the Friday (10/07).
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.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now