Oracle SQL: Retrieve data for previous week

Tags:
Oracle
SQL
I am trying to retrieve data for the previous week. I need to get the previous week starting on Monday and ending on Sunday. How can I retrieve the data from Monday to Sunday? For example, today is 10-Aug-2016. So, I need details from 1-Aug-2016 to 5-Aug-2016 as week day, and 6-Aug-2016 to 7-Aug-2016 as Weekend.


Software/Hardware used:
Oracle SQL Query
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Sounds like a homework question. Post your code and any errors you are getting. We need to know file/table names field/columns names as well. We can help you understand where your code went wrong and helping your coding skills get better by pointing out the issue with your code so you can fix it.
    129,900 pointsBadges:
    report
  • carlosdl
    At the beginning you say "I need to get the previous week starting on Monday and ending on Sunday", but then you say "
    So, I need details from 1-Aug-2016 to 5-Aug-2016 as week day, and 6-Aug-2016 to 7-Aug-2016 as Weekend". So do you want the whole week as you mentioned at the beginning or week days and weekends separated?

    Also, since we don't know the structure of your tables, we cannot give you a concrete suggestion.

    You can use the TO_CHAR function with the system date using the 'd' or 'day' format models to determine the current day of week and based on that make the necessary calculations to determine the date ranges you need to retrieve.

    SELECT TO_CHAR(sysdate, 'day')
    FROM dual;
    
    OR
    
    SELECT TO_CHAR(sysdate, 'd')
    FROM dual;

    84,580 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: