Solved

How to get previous week friday based on sysdate.

Posted on 2016-10-12
2
49 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create table from select - oracle 6 67
Oracle DB monitor SW 21 72
date show only hh:mm 2 37
PL/SQl Expanding the WHERE statement in query 3 33
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…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

756 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