Solved

How to get previous week friday based on sysdate.

Posted on 2016-10-12
2
52 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Expert Comment

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

717 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