Challenge - 5 Problems
TO_CHAR Date Formatting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Formatting date to show full month name and year
What is the output of this query?
SELECT TO_CHAR(DATE '2024-06-15', 'Month YYYY');PostgreSQL
SELECT TO_CHAR(DATE '2024-06-15', 'Month YYYY');
Attempts:
2 left
💡 Hint
The format 'Month' returns the full month name padded with spaces to 9 characters.
✗ Incorrect
The 'Month' format returns the full month name padded with spaces to 9 characters, so 'June' is padded with spaces to 9 characters, followed by a space and the year.
❓ query_result
intermediate2:00remaining
Using TO_CHAR to format time with AM/PM
What is the output of this query?
SELECT TO_CHAR(TIMESTAMP '2024-06-15 14:30:00', 'HH12:MI AM');PostgreSQL
SELECT TO_CHAR(TIMESTAMP '2024-06-15 14:30:00', 'HH12:MI AM');
Attempts:
2 left
💡 Hint
HH12 returns hour in 12-hour format, AM shows AM or PM.
✗ Incorrect
14:30 in 24-hour time is 2:30 PM in 12-hour format, so output is '02:30 PM'.
📝 Syntax
advanced2:00remaining
Identify the syntax error in TO_CHAR date format
Which option contains a syntax error in the TO_CHAR format string?
Query example:
Query example:
SELECT TO_CHAR(DATE '2024-06-15', ''); Attempts:
2 left
💡 Hint
Check if the format string uses valid date patterns.
✗ Incorrect
The format 'YYYY-MM-DD-DX' contains invalid 'DX' which causes a syntax error.
❓ query_result
advanced2:00remaining
Output of TO_CHAR with day of week and day number
What is the output of this query?
SELECT TO_CHAR(DATE '2024-06-15', 'Dy DD');PostgreSQL
SELECT TO_CHAR(DATE '2024-06-15', 'Dy DD');
Attempts:
2 left
💡 Hint
'Dy' returns abbreviated day name, 'DD' returns day of month as two digits.
✗ Incorrect
'2024-06-15' is a Saturday, so 'Dy' returns 'Sat' and 'DD' returns '15'.
🧠 Conceptual
expert2:00remaining
Understanding padding behavior in TO_CHAR date formatting
Which statement about TO_CHAR date formatting padding is TRUE?
Attempts:
2 left
💡 Hint
Check how TO_CHAR handles padding for month names and abbreviations.
✗ Incorrect
The 'Month' format pads the full month name with spaces to 9 characters. 'Mon' does not pad with zeros, 'DD' pads with zeros, and 'YYYY' returns 4 digits without padding.