How to convert sysdate in Oracle to a string?

You can use the TO_CHAR() function and specify the appropriate date format template as the second parameter when converting sysdate to a string.

Below are some common examples of date format templates:

‘YYYY-MM-DD’: Year-Month-Day (e.g. 2022-01-01)

‘DD-MON-YYYY’: Day-Month-Year (e.g. 01-JAN-2022)

‘MM/DD/YYYY HH:MI:SS AM’: Month/Day/Year Hour:Minute:Second AM/PM (e.g. 01/01/2022 12:34:56 PM)

Here is an example of converting sysdate to a string using the ‘YYYY-MM-DD HH24:MI:SS’ format template:

SELECT TO_CHAR(sysdate, 'YYYY-MM-DD HH24:MI:SS') AS current_date FROM dual;

This will return a date-time string similar to 2022-01-01 12:34:56. You can adjust the format template to meet your specific needs.

bannerAds