CURRENT_DATE returns the current session-timezone date as a value of type date.
CURRENT_DATE yields the calendar date based on the session’s time zone, with the data type date
. It contains no time-of-day component, so comparisons and formatting are straightforward.
Run SELECT CURRENT_DATE;
to see today’s date. In a script, assign an alias for clarity: SELECT CURRENT_DATE AS today;
.
CURRENT_DATE is a SQL standard special register—no parentheses needed. You can optionally cast or alias it. See full syntax below.
Yes. Use it in WHERE
clauses to fetch records created today: ... WHERE created_at::date = CURRENT_DATE
.
Add or subtract interval
s: CURRENT_DATE + INTERVAL '7 days'
returns the date one week ahead; subtract for past dates.
It reflects the session time zone. Execute SHOW TIME ZONE;
or set one with SET TIME ZONE 'America/New_York';
before calling CURRENT_DATE.
Cast timestamp columns to date
before comparison, index created_at
when filtering by date, and avoid wrapping CURRENT_DATE in functions that prevent index use.
No. NOW()
(or CURRENT_TIMESTAMP
) returns a timestamp with date and time. CURRENT_DATE
returns only the date portion.
No. Its value is fixed at the start of the transaction, ensuring consistency across statements.
Temporarily set the session time zone: SET TIME ZONE 'UTC'; SELECT CURRENT_DATE;
. Remember to reset it afterward if needed.