postgres convert date to string 1

postgres convert date to string

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

Here is what the above code is Doing:
1. We’re using the TO_CHAR function to convert the SYSDATE function to a string.
2. We’re using the ‘YYYY-MM-DD’ format model to specify the format of the date.
3. We’re using the dual table to select from.

The dual table is a special one-row, one-column table present by default in Oracle and other database installations. It’s useful for selecting a pseudo column such as SYSDATE or USER.

Here’s the output of the above code:

‘2018-01-01’

Similar Posts