0
0
PostgreSQLquery~20 mins

EXTRACT function for date parts in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
EXTRACT Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1:30remaining
Extracting the year from a timestamp
What is the output of this query?
SELECT EXTRACT(YEAR FROM TIMESTAMP '2023-11-15 08:30:00');
PostgreSQL
SELECT EXTRACT(YEAR FROM TIMESTAMP '2023-11-15 08:30:00');
A15
B11
C08
D2023
Attempts:
2 left
💡 Hint
EXTRACT gets a specific part of the date/time, like year, month, or day.
query_result
intermediate
1:30remaining
Extracting the month from a date
What does this query return?
SELECT EXTRACT(MONTH FROM DATE '2024-02-29');
PostgreSQL
SELECT EXTRACT(MONTH FROM DATE '2024-02-29');
A29
B2
C2024
D0
Attempts:
2 left
💡 Hint
MONTH extracts the month number from the date.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in EXTRACT usage
Which option contains a syntax error when using EXTRACT in PostgreSQL?
ASELECT EXTRACT(HOUR, TIMESTAMP '2023-05-10 12:00:00');
BSELECT EXTRACT(DAY FROM TIMESTAMP '2023-05-10 12:00:00');
CSELECT EXTRACT(MINUTE FROM TIMESTAMP '2023-05-10 12:00:00');
DSELECT EXTRACT(SECOND FROM TIMESTAMP '2023-05-10 12:00:00');
Attempts:
2 left
💡 Hint
Check the syntax: EXTRACT expects the part and source separated by FROM.
query_result
advanced
1:30remaining
Extracting fractional seconds from a timestamp
What is the output of this query?
SELECT EXTRACT(SECOND FROM TIMESTAMP '2023-07-20 14:23:45.678');
PostgreSQL
SELECT EXTRACT(SECOND FROM TIMESTAMP '2023-07-20 14:23:45.678');
A0.678
B678
C45.678
D45
Attempts:
2 left
💡 Hint
EXTRACT(SECOND) returns seconds including fractional part.
🧠 Conceptual
expert
2:30remaining
Understanding EXTRACT with time zone aware timestamps
Given the timestamp with time zone '2023-12-31 23:00:00+02', what does this query return?
SELECT EXTRACT(HOUR FROM TIMESTAMPTZ '2023-12-31 23:00:00+02');
PostgreSQL
SELECT EXTRACT(HOUR FROM TIMESTAMPTZ '2023-12-31 23:00:00+02');
A23
B21
C1
D0
Attempts:
2 left
💡 Hint
EXTRACT returns the hour part in the local time of the timestamp, ignoring time zone offset.