Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    153

    Unanswered: Find the date of the previous day of the current date

    Hi,

    I would like to find the date of the previous day (last week) of the current date.

    like

    1. if current date is 09-Oct-2016 (Sunday), want to get the date of previous day 'Thursday'. .. for this answer will be '06 Oct 2016'
    2. if current date is 09-Oct-2016 (Sunday), want to get the date of previous day Wednesday'... for this answer will be '05 Oct 2016'

    Searched google, but didn't get any suitable answer.


    Thanks in advance,
    JD

  2. #2
    Join Date
    Jun 2004
    Posts
    796
    Provided Answers: 1
    Not sure how you're searching - google found "About 478,000 results" for me...

    Anyway, this was the first hit that was returned. Is this what you're after?

    http://stackoverflow.com/questions/1...on-todays-date
    90% of users' problems can be resolved by punching them - the other 10% by switching off their PCs.

  3. #3
    Join Date
    Oct 2007
    Posts
    48
    Provided Answers: 3
    how do you get previous day of Sunday being a Thursday?

  4. #4
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Something like this?

    Code:
    SQL> alter session set nls_date_language = english;
    
    Session altered.
    
    SQL> alter session set nls_date_format = 'dd mon yyyy';
    
    Session altered.
    
    SQL> set verify off
    SQL>
    SQL> with previous_week as
      2  (select (trunc(sysdate) - level + 1) datum,
      3          to_char(trunc(sysdate) - level + 1, 'fmDay') dan
      4   from dual
      5   connect by level <= 7
      6  )
      7  select * from previous_week
      8  where dan = '&par_dan';
    Enter value for par_dan: Thursday
    
    DATUM       DAN
    ----------- ------------------------------------
    06 oct 2016 Thursday
    
    SQL> /
    Enter value for par_dan: Wednesday
    
    DATUM       DAN
    ----------- ------------------------------------
    05 oct 2016 Wednesday
    
    SQL>

  5. #5
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Actually oracle has a function for that.

    select next_day(trunc(sysdate-6),'THU') FROM DUAL;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •