#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Date Manipulation in Oracle SQl


    Please help ......why doesn't the following SQL doesn't return any rows. (column1 is a 'date' datatype)

    select * from table1
    where to_char(column1, 'dd-mon-yyyy') = to_char(sysdate + 3 , 'dd-mon-yyyy')


    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Why are you converting to character anyway?
    Why not just compare the dates?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0
    Your doing Complicated thing.. Why you are going to convert to char? Instead of date.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    14
    Rep Power
    0
    Originally Posted by hrs2012
    Please help ......why doesn't the following SQL doesn't return any rows. (column1 is a 'date' datatype)

    select * from table1
    where to_char(column1, 'dd-mon-yyyy') = to_char(sysdate + 3 , 'dd-mon-yyyy')


    Thanks
    TRUNC() is probably better here than TO_CHAR(). Try this:

    Code:
    select * from table1 
    where TRUNC(column1) = TRUNC(sysdate) + 3

IMN logo majestic logo threadwatch logo seochat tools logo