September 27, 2024
The following page shows the most commonly used PostgreSQL date functions that allow you to manipulate date and time values effectively.
Function | Return Type | Description |
---|---|---|
age | interval | Calculate ages between two timestamps and returns a “symbolic” result which uses years and months |
age | interval | Calculate ages between current date (at midnight) and a timestamp and returns a “symbolic” result which uses years and months |
clock_timestamp | timestamptz | Return the current date and time which changes during statement execution |
current_date | date | Return the current date |
current_time | timestamptz | Return the current time |
current_timestamp | timestamptz | Return the current date and time with time zone at which the current transaction starts |
date_part | double precision | Get a field of a timestamp or an interval e.g., year, month, day, etc. |
date_trunc | timestamp | Return a timestamp truncated to a specified precision |
extract | double precision | Same as date_part() function |
isfinite | boolean | Check if a date, a timestamp, or an interval is finite or not (not +/-infinity) |
justify_days | interval | Adjust interval so 30-day time periods are represented as months |
justify_hours | interval | Adjust interval so 24-hour time periods are represented as days |
justify_interval | interval | Adjust interval using justify_days and justify_hours, with additional sign adjustments |
localtime | time | Return the time at which the current transaction start |
localtimestamp | timestamp | Return the date and time at which the current transaction start |
make_interval | interval | Create an interval from the provided interval’s components |
make_time | time | Create a time from hour, minute, and second |
now | timestamptz | Return the date and time with time zone at which the current transaction start |
statement_timestamp | timestamptz | Return the current date and time at which the current statement executes |
timeofday | text | Return the current date and time, like clock_timestamp, as a text string |
transaction_timestamp | timestamptz | Same as NOW() function |
to_date | date | Convert a string to a date |
to_timestamp | timestamptz | Convert a string to a timestamp |