Solved

How to get previous week friday based on sysdate.

Posted on 2016-10-12
2
25 Views
Last Modified: 2016-10-23
How to get previous week friday based on sysdate.  We are planning to include this logic on a job that runs daily.

Please advise !
0
Comment
Question by:d27m11y
2 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41841054
Try this:
select next_day(sysdate-7,'FRIDAY') from dual;
1
 
LVL 34

Accepted Solution

by:
johnsone earned 500 total points
ID: 41841769
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:
WITH x 
     AS (SELECT To_date('10022016', 'mmddyyyy') + LEVEL - 1 dt 
         FROM   dual 
         CONNECT BY LEVEL < 8) 
SELECT dt, 
       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).
1

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Combining the output of 2 oracle queries 2 47
Pl/SQL Query 31 62
Oracle Subquery bad Join 11 46
Oracle 12c patching 1 38
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now