0
0
PostgreSQLquery~20 mins

CURRENT_DATE, CURRENT_TIMESTAMP, NOW() in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Timestamp Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1:30remaining
What is the output of CURRENT_DATE?
Consider the following SQL query run on April 15, 2024:
SELECT CURRENT_DATE;
What will be the output?
PostgreSQL
SELECT CURRENT_DATE;
A2024-04-15
B2024-04-15 00:00:00
C2024-04-15 12:00:00
DError: function CURRENT_DATE() does not exist
Attempts:
2 left
💡 Hint
CURRENT_DATE returns only the date part without time.
query_result
intermediate
1:30remaining
What does CURRENT_TIMESTAMP return?
Given the query below executed on April 15, 2024 at 14:30:45.123456:
SELECT CURRENT_TIMESTAMP;
What is the expected output format?
PostgreSQL
SELECT CURRENT_TIMESTAMP;
AError: CURRENT_TIMESTAMP is not a valid function
B2024-04-15
C14:30:45
D2024-04-15 14:30:45.123456+00
Attempts:
2 left
💡 Hint
CURRENT_TIMESTAMP returns date and time with timezone.
query_result
advanced
2:00remaining
How does NOW() differ from CURRENT_TIMESTAMP?
Run these two queries at the same moment:
SELECT NOW();
SELECT CURRENT_TIMESTAMP;
What is the difference in their outputs?
PostgreSQL
SELECT NOW();
SELECT CURRENT_TIMESTAMP;
ABoth return the exact same timestamp with timezone.
BNOW() returns timestamp without timezone; CURRENT_TIMESTAMP returns with timezone.
CNOW() returns only the time; CURRENT_TIMESTAMP returns date and time.
DNOW() returns the time when the transaction started; CURRENT_TIMESTAMP returns the current time.
Attempts:
2 left
💡 Hint
In PostgreSQL, NOW() is an alias for CURRENT_TIMESTAMP.
📝 Syntax
advanced
2:00remaining
Which query correctly extracts only the date part from NOW()?
You want to get only the date (YYYY-MM-DD) from the current timestamp using NOW(). Which query is correct?
ASELECT DATE(NOW());
BSELECT NOW()::date;
CAll of the above
DSELECT TO_CHAR(NOW(), 'YYYY-MM-DD');
Attempts:
2 left
💡 Hint
PostgreSQL allows multiple ways to extract date from timestamp.
🧠 Conceptual
expert
2:30remaining
Why might CURRENT_TIMESTAMP and NOW() return different values inside a transaction?
In PostgreSQL, consider a transaction that runs multiple queries using NOW() and CURRENT_TIMESTAMP. Which statement is true?
AThey always return the exact current time at each call, even inside a transaction.
BThey return the time when the transaction started, so all calls inside the transaction return the same timestamp.
CNOW() returns the current time at each call; CURRENT_TIMESTAMP returns the transaction start time.
DThey return NULL inside transactions.
Attempts:
2 left
💡 Hint
PostgreSQL treats NOW() and CURRENT_TIMESTAMP as transaction start time.