How can convert date format in oracle?

by muriel.schmidt , in category: MySQL , 3 months ago

How can convert date format in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 3 months ago

@muriel.schmidt 

To convert date format in Oracle, you can use the TO_DATE() and TO_CHAR() functions.


If you have a date stored in a different format and you want to convert it to a different format, you can use the TO_DATE() function to convert the date to a standard format and then use the TO_CHAR() function to convert it to the desired format.


For example, if you have a date stored as '01-JAN-2020' and you want to convert it to '2020-01-01', you can use the following query:

1
2
SELECT TO_CHAR(TO_DATE('01-JAN-2020', 'DD-MON-YYYY'), 'YYYY-MM-DD') AS new_date
FROM dual;


This will return '2020-01-01' as the new date format.


You can also use the TO_CHAR() function directly on a date column in a table to convert the date format while retrieving data:

1
2
SELECT TO_CHAR(date_column, 'YYYY-MM-DD') AS new_date
FROM your_table;


This will return the date in 'YYYY-MM-DD' format from the date column in the table.