Last post Aug 07, 2012 01:52 AM by Ajay2707
Aug 06, 2012 10:41 PM|-_-|LINK
why i convert the string to date format by to_date(field_name,'dd-mm-yyyy') from table_A
actully my date format save in database is yyyymmdd. (20120622)
why it returns 0622-12-20 00:00:00:00.0
how can i convert to dd-mm-yyyy
Aug 06, 2012 10:54 PM|Prashant Kumar|LINK
In a database, a date is stored as a number - it does not have any format. The format is applied to the date by the application that you use to view the date.
From what I understand, you have a date saved as a string in the database (20120622). To convert this to a date you would do to_date(field_name,'yyyymmdd'). To output as a string in the format dd-mm-yyyy you would do to_char(to_date(field_name,'yyyymmdd'),'dd-mm-yyyy')
Having said that, you should never store a date as a string in the database.
Aug 06, 2012 10:57 PM|Dan Bracuk|LINK
Save your dates as dates. When selecting them back, you can use to_char in your query or you can format it with your application code.
Aug 07, 2012 01:52 AM|Ajay2707|LINK
SELECT TO_CHAR(SYSDATE, 'DD/MM/YYYY') from dual;
Oracle's default date format is YYYY-MM-DD. check this:
select SYSDATE from dual;