-
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.
-
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.
-
SQL> select to_char(to_date('20021231','yyyymmdd'),'dd/mm/yyyy') from dual;
TO_CHAR(TO
----------
31/12/2002
-
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|