How to convert Oracle timestamp to a string?

In Oracle, you can convert a timestamp to a string using the TO_CHAR function.

The sample code is shown as follows:

SELECT TO_CHAR(timestamp_column, 'YYYY-MM-DD HH24:MI:SS') AS timestamp_string
FROM your_table;

In the code above, timestamp_column refers to the column containing timestamps, while your_table refers to the table containing timestamps. ‘YYYY-MM-DD HH24:MI:SS’ is the date format model used to specify the output string format. Feel free to adjust the date format model as needed.

In addition, there are other date format model options available, such as:

  1. YYYY: A four-digit year.
  2. MM: Month (01-12)
  3. DD: Date (01-31)
  4. HH24: Hours (00-23)
  5. MI: minutes (00-59)
  6. SS: seconds (00-59)

You can customize the date format by using these options as needed.

Please note that if a format model is specified when converting a timestamp to a string, rather than using the default format, the output string will be formatted according to the specified format.

bannerAds