Challenge - 5 Problems
TO_DATE and TO_TIMESTAMP Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of this TO_DATE query?
Given the query:
What is the output?
SELECT TO_DATE('2024-06-15', 'YYYY-MM-DD');What is the output?
PostgreSQL
SELECT TO_DATE('2024-06-15', 'YYYY-MM-DD');
Attempts:
2 left
💡 Hint
TO_DATE returns a date type without time part.
✗ Incorrect
TO_DATE converts a string to a date type. It returns only the date part without time.
❓ query_result
intermediate1:30remaining
What does this TO_TIMESTAMP query return?
Consider this query:
What is the output?
SELECT TO_TIMESTAMP('2024-06-15 14:30:45', 'YYYY-MM-DD HH24:MI:SS');What is the output?
PostgreSQL
SELECT TO_TIMESTAMP('2024-06-15 14:30:45', 'YYYY-MM-DD HH24:MI:SS');
Attempts:
2 left
💡 Hint
TO_TIMESTAMP returns a timestamp without time zone.
✗ Incorrect
TO_TIMESTAMP parses the string into a timestamp without time zone.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in TO_DATE usage?
Identify which query will cause a syntax error:
Attempts:
2 left
💡 Hint
Check if the format matches the input string exactly.
✗ Incorrect
Option D uses format 'YYYY-DD-MM' but input is '2024-06-15' which is 'YYYY-MM-DD'. This mismatch causes an error.
❓ query_result
advanced2:00remaining
What is the output of this TO_TIMESTAMP with fractional seconds?
Given:
What is the output?
SELECT TO_TIMESTAMP('2024-06-15 14:30:45.123456', 'YYYY-MM-DD HH24:MI:SS.US');What is the output?
PostgreSQL
SELECT TO_TIMESTAMP('2024-06-15 14:30:45.123456', 'YYYY-MM-DD HH24:MI:SS.US');
Attempts:
2 left
💡 Hint
US means microseconds in the format string.
✗ Incorrect
The format 'SS.US' parses seconds and microseconds, so fractional seconds are preserved.
🧠 Conceptual
expert2:30remaining
Why does TO_DATE discard time information while TO_TIMESTAMP preserves it?
Choose the best explanation:
Attempts:
2 left
💡 Hint
Think about the data types returned by each function.
✗ Incorrect
TO_DATE returns a date type that stores only date parts. TO_TIMESTAMP returns a timestamp type that stores date and time parts.