Introduction
TO_CHAR helps you change how dates look by turning them into text in the style you want.
TO_CHAR(date_value, 'format_pattern')TO_CHAR(current_date, 'YYYY-MM-DD')TO_CHAR(current_date, 'Month DD, YYYY')TO_CHAR(current_date, 'DY')TO_CHAR(current_date, 'HH24:MI:SS')SELECT TO_CHAR(DATE '2024-06-15', 'YYYY-MM-DD') AS formatted_date, TO_CHAR(DATE '2024-06-15', 'Month DD, YYYY') AS long_format, TO_CHAR(DATE '2024-06-15', 'DY') AS short_day_name;
TO_CHAR do when used with a date?TO_CHAR function is used to convert dates or numbers into text with a specific format.TO_CHAR in PostgreSQL?TO_CHAR(date_value, 'format_string') where the format is a string in single quotes.SELECT TO_CHAR(DATE '2024-06-15', 'FMMonth DD, YYYY');
SELECT TO_CHAR(NOW(), YYYY-MM-DD);
TO_CHAR?NOW() or CURRENT_TIMESTAMP for current timestamp. SELECT TO_CHAR(NOW(), 'DD/MM/YYYY HH24:MI'); matches the format exactly.Pass the test and this pattern moves unknown