Date/Time functions

Devart ODBC Driver for PostgreSQL supports the following date/time operators and functions for working with dates, times, timestamps, and intervals.
They cover arithmetic, binning, extraction, truncation, and construction of date/time values, including time zone–aware operations.

Date/time operators

Operator Return type Description
date + integer date Adds a number of days to a date.
date + interval timestamp Adds an interval to a date and returns a timestamp.
date + time timestamp Adds a time value to a date and returns a timestamp.
interval + interval interval Adds two intervals.
timestamp + interval timestamp Adds an interval to a timestamp.
time + interval time Adds an interval to a time value.
- interval interval Negates an interval (changes its sign).
date - date integer Subtracts two dates, returning the number of days between them.
date - integer date Subtracts a number of days from a date.
date - interval timestamp Subtracts an interval from a date and returns a timestamp.
time - time interval Subtracts two times-of-day, returning the interval between them.
time - interval time Subtracts an interval from a time value.
timestamp - interval timestamp Subtracts an interval from a timestamp.
interval - interval interval Subtracts one interval from another.
timestamp - timestamp interval Subtracts two timestamps, returning the interval between them.
interval * double precision interval Multiplies an interval by a scalar value.
interval / double precision interval Divides an interval by a scalar value.

Date/time functions

Function Return type Description
age(timestamp, timestamp) interval Subtracts two timestamps, returning a symbolic interval expressed in years, months, and days.
age(timestamp) interval Subtracts the given timestamp from the current date (at midnight), returning a symbolic interval.
clock_timestamp() timestamptz Returns the current date and time; the value continues to change during statement execution.
current_date date Returns the current date (without a time component).
current_time([integer]) timetz Returns the current time of day with time zone, optionally with limited fractional second precision.
current_timestamp([integer]) timestamptz Returns the current date and time with time zone, fixed at the start of the current transaction, optionally with limited precision.
date_add(timestamptz, interval, [text]) timestamptz Adds an interval to a timestamp with time zone, handling Daylight Saving Time (DST) according to the optional time zone name.
date_bin(interval, timestamp, timestamp) timestamp Bins (rounds down) a timestamp into intervals of the given size, aligned to the specified origin timestamp.
date_part(text, timestamp/interval) double precision Returns the specified field (for example, hour, month, or day of week) from a timestamp or interval (equivalent to extract).
date_subtract(timestamptz, interval, [text]) timestamptz Subtracts an interval from a timestamp with time zone, handling DST according to the optional time zone name.
date_trunc(text, timestamp/interval, [text]) same as input type Truncates a date, timestamp, or interval to the specified precision (for example, hour, day); for timestamptz, an optional time zone name can be specified.
extract(field from timestamp/interval) numeric Returns a specified field (such as year, month, day, hour) from a timestamp or interval.
isfinite(date/timestamp/interval) boolean Returns true if the value is finite (not +infinity or -infinity).
justify_days(interval) interval Normalizes an interval by converting 30-day periods into whole months.
justify_hours(interval) interval Normalizes an interval by converting 24-hour periods into whole days.
justify_interval(interval) interval Applies both justify_days and justify_hours, and adjusts signs to produce a normalized interval.
localtime([integer]) time Returns the current time of day without time zone, optionally with limited fractional second precision.
localtimestamp([integer]) timestamp Returns the current date and time without time zone, fixed at the start of the current transaction.
make_date(year, month, day) date Constructs a date from integer year, month, and day components.
make_interval(...) interval Constructs an interval from individual components such as years, months, days, hours, minutes, and seconds.
make_time(hour, min, sec) time Constructs a time value from hour, minute, and second components.
make_timestamp(...) timestamp Constructs a timestamp (without time zone) from date and time components.
make_timestamptz(..., [timezone]) timestamptz Constructs a timestamp with time zone from date and time components and an optional time zone name.
now() timestamptz Returns the current date and time with time zone, fixed at the start of the current transaction (same as transaction_timestamp).
statement_timestamp() timestamptz Returns the current date and time with time zone, fixed at the start of the current statement.
timeofday() text Returns the current date and time as a text string, similar to clock_timestamp().
transaction_timestamp() timestamptz Returns the current date and time with time zone, fixed at the start of the current transaction.
to_timestamp(double precision) timestamptz Converts a Unix epoch value (seconds since 1970-01-01 00:00:00+00) to a timestamp with time zone.