Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    92

    Unanswered: yesterday's date

    Hi All,

    I have a sql query which returns the date in the format YYYYMMDD.for example the query returns 20100211
    How do I calculate yesterday's date based on the date the query returns.

    Thanks
    Pavan

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by pavan_test View Post
    I have a sql query which returns the date in the format YYYYMMDD
    A DATE does not have a "format"...

    If you are using the date (or timestamp) datatype you can simply subtract 1:[code]SELECT sysdate - 1
    FROM dual[/quote]Will return yesterday's date (at the same time as "right now")

    If you are dealing with a string you'll need to first convert the string into a date using the to_date() function and then apply the above calculation.

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
     1* select to_char(trunc(sysdate-1),'YYYY-MM-DD') YESTERDAY FROM DUAL
    SQL> /
    
    YESTERDAY
    ----------
    2010-02-10
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

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