Oracle TO_CHAR: Convert Date to String

In Oracle, you can use the TO_CHAR function to convert a date into a specific format string. The syntax is as follows:

TO_CHAR(date, format)

In this case, date is the date to be converted, and format is the specified date format, which can be one of the following:

  1. YYYY-MM-DD HH24:MI:SS: Year-Month-Day Hour:Minute:Second
  2. YYYY-MM-DD HH:MI:SS AM:Year-Month-Day 12-Hour:Minute:Second AM/PM
  3. MM/DD/YYYY HH:MI:SS AM:Month/Day/Year Hour:Minute:Second AM/PM
  4. “Wait a moment.”

For example, converting the current date into a string with the format YYYY-MM-DD:

SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD') FROM dual;

This will return a string similar to ‘2022-01-10’.

bannerAds