Contents
current_date
current_date
is a system function returning the date
at which the current transaction started.
current_date
was added in PostgreSQL 6.3.
Usage
current_date → date
Despite its name, current_date
returns the date when the current transaction was started, not the actual date the function was executed (this can be retrieved via clock_timestamp()
).
Note that current_date
cannot be invoked as current_date()
.
Change history
- PostgreSQL 6.2
- added (commit f10b6392)
Examples
Basic execution example for current_date
:
postgres=# SELECT current_date; current_date -------------- 2021-06-17 (1 row)
current_date
will always report the same date as transaction_timestamp()
, and (if executed in an implicit transaction) the same date as statement_timestamp()
:
postgres=# SELECT current_date, transaction_timestamp(), statement_timestamp(), clock_timestamp()\gx -[ RECORD 1 ]---------+------------------------------ current_date | 2021-06-19 transaction_timestamp | 2021-06-19 08:48:18.386946+09 statement_timestamp | 2021-06-19 08:48:18.386946+09 clock_timestamp | 2021-06-19 08:48:18.387096+09
In practice the date returned by all of these functions will usually be the same, but may of course differ for transactions started close to the end od the day.
The variant current_date()
is not valid:
postgres=# SELECT current_date(); ERROR: syntax error at or near "(" LINE 1: SELECT current_date(); ^
References
- PostgreSQL documentation: Date/Time Functions
- PostgreSQL documentation: Current Date/Time