DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Using TO_DATE format in select statement

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    17

    Using TO_DATE format in select statement

    Hello,
    Pls am using TO_DATE function in my select stt. But its returning the wrong dates for me. In the database a text field contains 20021231. i want to convert it to date format and am using this format

    TO_DATE(ind_val,'dd/mm/yyyy')

    I want the format above to return 31/12/2001 from 20021231 but its returning 20-feb-31.

    Pls anyone have and idea how i can return exactly dd/mm/yyyy from 20021231.

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    you need to specify the format of the data in your column

    TO_DATE(ind_val,'yyyymmdd')

    and set your nls_date_format to

    alter session set nls_date_format = 'DD/MM/YYYY' to display it how you want it
    Last edited by davey23uk; 04-29-2005 at 08:11 AM.

  3. #3
    Join Date
    Apr 2003
    Posts
    353
    SQL> select to_char(to_date('20021231','yyyymmdd'),'dd/mm/yyyy') from dual;

    TO_CHAR(TO
    ----------
    31/12/2002

  4. #4
    Join Date
    Apr 2005
    Posts
    17
    thanx. It worked.

  5. #5
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    A word to the wise:

    If you're experimenting, testing etc in SQL*Plus then setting NLS_DATE_FORMAT, as suggested by davey, is ideal.

    If you're writing an "application", the only sure-fire way to get it to always work, is to fully specify the date formats as engiri did.
    "The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman

Posting Permissions

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


Click Here to Expand Forum to Full Width