0
0
PostgreSQLquery~20 mins

TO_CHAR for date formatting in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TO_CHAR Date Formatting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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');
A'June 2024'
B'Jun 2024'
C'06 2024'
D'2024-06-15'
Attempts:
2 left
💡 Hint
The format 'Month' returns the full month name padded with spaces to 9 characters.
query_result
intermediate
2: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');
A'02:30 AM'
B'02:30 PM'
C'14:30 PM'
D'14:30'
Attempts:
2 left
💡 Hint
HH12 returns hour in 12-hour format, AM shows AM or PM.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in TO_CHAR date format
Which option contains a syntax error in the TO_CHAR format string?

Query example:
SELECT TO_CHAR(DATE '2024-06-15', '');
A'YYYY-MM-DD'
B'YYYY/MM/DD'
C'YYYY-MM-DD-DX'
D'YY-MM-DD'
Attempts:
2 left
💡 Hint
Check if the format string uses valid date patterns.
query_result
advanced
2: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');
A'Sat 15th'
B'Saturday 15'
C'Su 15'
D'Sat 15'
Attempts:
2 left
💡 Hint
'Dy' returns abbreviated day name, 'DD' returns day of month as two digits.
🧠 Conceptual
expert
2:00remaining
Understanding padding behavior in TO_CHAR date formatting
Which statement about TO_CHAR date formatting padding is TRUE?
AThe 'Month' format pads the month name with spaces to 9 characters by default.
BThe 'Mon' format pads the month abbreviation with zeros to 3 characters.
CThe 'DD' format pads the day number with spaces to 2 characters.
DThe 'YYYY' format pads the year with spaces to 5 characters.
Attempts:
2 left
💡 Hint
Check how TO_CHAR handles padding for month names and abbreviations.