0
0
PostgreSQLquery~10 mins

Date, time, and timestamp types in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the current date in PostgreSQL.

PostgreSQL
SELECT [1];
Drag options to blanks, or click blank then click option'
ANOW()
BCURRENT_DATE
CCURRENT_TIME
DTIMESTAMP
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOW() returns date and time, not just date.
Using CURRENT_TIME returns only the time part.
2fill in blank
medium

Complete the code to select the current timestamp with time zone in PostgreSQL.

PostgreSQL
SELECT [1];
Drag options to blanks, or click blank then click option'
ACURRENT_DATE
BLOCALTIME
CCURRENT_TIME
DCURRENT_TIMESTAMP
Attempts:
3 left
💡 Hint
Common Mistakes
Using CURRENT_DATE returns only the date.
Using CURRENT_TIME returns only the time.
3fill in blank
hard

Fix the error in the code to cast a string to a timestamp type.

PostgreSQL
SELECT '2024-06-01 15:30:00'::[1];
Drag options to blanks, or click blank then click option'
Adate
Binterval
Ctimestamp
Dtime
Attempts:
3 left
💡 Hint
Common Mistakes
Casting to date removes the time part.
Casting to time removes the date part.
4fill in blank
hard

Fill both blanks to extract the time part from a timestamp in PostgreSQL.

PostgreSQL
SELECT [1](my_timestamp AS [2]) AS time_only FROM events WHERE my_timestamp > CURRENT_DATE;
Drag options to blanks, or click blank then click option'
ACAST
BDATE
CTIME
DNOW()
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOW() instead of CAST.
Using DATE instead of TIME for casting.
5fill in blank
hard

Fill all three blanks to create a timestamp from separate date and time strings in PostgreSQL.

PostgreSQL
SELECT TO_TIMESTAMP([1] || ' ' || [2], [3]) AS full_timestamp;
Drag options to blanks, or click blank then click option'
A'2024-06-01'
B'15:30:00'
C'YYYY-MM-DD HH24:MI:SS'
D'06/01/2024'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format string.
Not concatenating date and time with a space.