0
0
PostgreSQLquery~10 mins

CURRENT_DATE, CURRENT_TIMESTAMP, NOW() in PostgreSQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - CURRENT_DATE, CURRENT_TIMESTAMP, NOW()
Start Query
Evaluate CURRENT_DATE
Evaluate CURRENT_TIMESTAMP
Evaluate NOW()
Return Results
End Query
The query evaluates CURRENT_DATE, CURRENT_TIMESTAMP, and NOW() functions step-by-step, returning the current date or timestamp values.
Execution Sample
PostgreSQL
SELECT CURRENT_DATE, CURRENT_TIMESTAMP, NOW();
This query returns the current date, the current timestamp with timezone, and the current timestamp with timezone again.
Execution Table
StepFunction EvaluatedResult TypeResult ExampleNotes
1CURRENT_DATEdate2024-06-15Returns only the date part, no time included
2CURRENT_TIMESTAMPtimestamp with time zone2024-06-15 14:23:45.123456+00Returns date and time with timezone
3NOW()timestamp with time zone2024-06-15 14:23:45.123456+00Equivalent to CURRENT_TIMESTAMP
4Return Resultsrow(2024-06-15, 2024-06-15 14:23:45.123456+00, 2024-06-15 14:23:45.123456+00)Query returns all three values as one row
💡 All functions evaluated and results returned as a single row.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
CURRENT_DATENULL2024-06-152024-06-152024-06-152024-06-15
CURRENT_TIMESTAMPNULLNULL2024-06-15 14:23:45.123456+002024-06-15 14:23:45.123456+002024-06-15 14:23:45.123456+00
NOW()NULLNULLNULL2024-06-15 14:23:45.123456+002024-06-15 14:23:45.123456+00
Key Moments - 3 Insights
Why does CURRENT_DATE return only the date without time?
CURRENT_DATE is designed to return only the date part, as shown in execution_table step 1, so it excludes time information.
Are CURRENT_TIMESTAMP and NOW() different in their output?
No, both CURRENT_TIMESTAMP and NOW() return the current date and time with timezone, as shown in execution_table steps 2 and 3, they produce the same result.
Why do CURRENT_TIMESTAMP and NOW() include timezone information?
Because they return 'timestamp with time zone' type, which includes timezone data to represent the exact moment globally, as seen in execution_table steps 2 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what type of value does CURRENT_DATE return at step 1?
ATimestamp with timezone
BTimestamp without timezone
CDate only
DTime only
💡 Hint
Check the 'Result Type' column in execution_table row 1.
At which step do CURRENT_TIMESTAMP and NOW() produce the same result?
AStep 2 and Step 3
BStep 4
CStep 1
DThey never produce the same result
💡 Hint
Look at the 'Result Example' and 'Notes' columns for steps 2 and 3 in execution_table.
If you only want the current date without time, which function should you use?
ACURRENT_TIMESTAMP
BCURRENT_DATE
CNOW()
DAll return the same
💡 Hint
Refer to the 'Result Type' and 'Notes' for CURRENT_DATE in execution_table step 1.
Concept Snapshot
CURRENT_DATE returns the current date only (no time).
CURRENT_TIMESTAMP returns current date and time with timezone.
NOW() is equivalent to CURRENT_TIMESTAMP.
Use CURRENT_DATE for date only, NOW() or CURRENT_TIMESTAMP for full timestamp.
All return values reflect the moment the query runs.
Full Transcript
This visual execution trace shows how PostgreSQL evaluates CURRENT_DATE, CURRENT_TIMESTAMP, and NOW() functions in a query. First, CURRENT_DATE returns only the date part without time. Then, CURRENT_TIMESTAMP returns the current date and time including timezone information. NOW() returns the same timestamp as CURRENT_TIMESTAMP. The query returns all three values as one row. Beginners often wonder why CURRENT_DATE excludes time and why CURRENT_TIMESTAMP and NOW() are the same; this trace clarifies those points by showing each step and the resulting values. Use CURRENT_DATE when you want just the date, and use NOW() or CURRENT_TIMESTAMP when you need the full timestamp with timezone.