PostgreSQL Date and Time Functions
This page lists the date and time functions that can be used to manipulate temporal values in PostgreSQL.
-
age
The PostgreSQLage()
function calculate the age according to the specified birthday and returns the age in the format ofx years x mons x days
. -
clock_timestamp
The PostgreSQLclock_timestamp()
function returns the date and time when this function was executed. Two executions ofclock_timestamp()
may return different values. -
current_date
The PostgreSQLcurrent_date
function returns the current system date in the formatYYYY-MM-DD
. -
current_time
The PostgreSQLcurrent_time
function returns the system time with time zone information in the formatHH:MM:SS.ssssss{+|-}ZZ
. -
current_timestamp
The PostgreSQLcurrent_timestamp()
function returns the current date and time (start of current transaction). -
date_bin
The PostgreSQLdate_bin()
function truncates the specified timestamp to the beginning of the nearest specified interval. -
date_part
The PostgreSQLdate_part()
function extracts the specified field from the specified timestamp or interval and returns the result. -
date_trunc
The PostgreSQLdate_trunc()
function truncates a specified timestamp or interval value to the specified part and returns the result. -
extract
The PostgreSQLextract()
function extracts the specified field from the specified timestamp or time interval and returns it. -
isfinite
The PostgreSQLisfinite()
function detects whether a given date, timestamp or interval value is finite. -
justify_days
The PostgreSQLjustify_days()
function converts the representation of time intervals, converting the number of days over 30 days to the number of months. -
justify_hours
The PostgreSQLjustify_hours()
function converts the representation of time intervals, converting hours over 24 hours into days. -
justify_interval
The PostgreSQLjustify_interval()
function converts the representation of time intervals, converting hours over 24 hours into days, and days over 30 days into months. -
localtime
The PostgreSQLlocaltime
function returns the current system time in the formatHH:MM:SS.ssssss
. -
localtimestamp
The PostgreSQLlocaltimestamp()
function returns the system date and time when the transaction started. -
make_date
The PostgreSQLmake_date()
function creates a date from the given year, month, and day fields. -
make_interval
The PostgreSQLmake_interval()
function creates an interval value from the given year, month, day, hour, minute, and second fields. -
make_time
The PostgreSQLmake_time()
function creates a time from the given hour, minute, and second fields. -
make_timestamp
The PostgreSQLmake_timestamp()
function creates a timestamp value from the given year, month, day, hour, minute, and second fields. -
make_timestamptz
The PostgreSQLmake_timestamptz()
function creates a timestamp value from the given year, month, day, hour, minute, second, timezone fields. -
now
The PostgreSQLnow()
function returns the system date and time when the current transaction started. -
pg_sleep
The PostgreSQLpg_sleep()
function suspends the execution of the current server process for the specified number of seconds. -
pg_sleep_for
The PostgreSQLpg_sleep_for()
function receives an interval parameter that pauses the execution of the current server process for the specified interval. -
pg_sleep_until
The PostgreSQLpg_sleep_until()
function receives a timestamp value and pauses the execution of the current server process until this specified moment. -
statement_timestamp
The PostgreSQLstatement_timestamp()
function returns the timestamp for the starting execution of the current statement. -
timeofday
The PostgreSQLtimeofday()
function returns a string representing the timestamp of when this function was executed. -
to_date
The PostgreSQLto_date()
function converts the specified string to a date value according to the given format. -
to_timestamp
The PostgreSQLto_timestamp()
function converts Unix epoch time to a standard timestamp with time zone information, or convert the specified string to timestamp according to the given format. -
transaction_timestamp
The PostgreSQLtransaction_timestamp()
function returns the system date and time when the current transaction started.