0
0
PostgreSQLquery~10 mins

Date arithmetic with intervals 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 add 5 days to the current date.

PostgreSQL
SELECT CURRENT_DATE [1] INTERVAL '5 days';
Drag options to blanks, or click blank then click option'
A*
B+
C/
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causes subtraction.
Using '*' or '/' causes syntax errors.
2fill in blank
medium

Complete the code to subtract 2 months from the current date.

PostgreSQL
SELECT CURRENT_DATE [1] INTERVAL '2 months';
Drag options to blanks, or click blank then click option'
A+
B*
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds the interval instead of subtracting.
Using '*' or '/' causes errors.
3fill in blank
hard

Fix the error in the code to add 10 hours to the timestamp '2024-01-01 08:00:00'.

PostgreSQL
SELECT TIMESTAMP '2024-01-01 08:00:00' [1] INTERVAL '10 hours';
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' subtracts the interval instead of adding.
Using '*' or '/' causes syntax errors.
4fill in blank
hard

Fill both blanks to subtract 15 days and then add 3 hours to the current timestamp.

PostgreSQL
SELECT CURRENT_TIMESTAMP [1] INTERVAL '15 days' [2] INTERVAL '3 hours';
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' to subtract days causes wrong results.
Using '*' or '/' causes errors.
5fill in blank
hard

Fill all three blanks to add 1 year, subtract 2 months, and add 10 days to the current date.

PostgreSQL
SELECT CURRENT_DATE [1] INTERVAL '1 year' [2] INTERVAL '2 months' [3] INTERVAL '10 days';
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' to add intervals causes wrong results.
Using '*' or '/' causes syntax errors.