9.9. Date/Time Functions and Operators

Table 9-28 shows the available functions for date/time value processing, with details appearing in the following subsections. Table 9-27 illustrates the behaviors of the basic arithmetic operators (+, *, etc.). For formatting functions, refer to Section 9.8. You should be familiar with the background information on date/time data types from Section 8.5.

All the functions and operators described below that take time or timestamp inputs actually come in two variants: one that takes time with time zone or timestamp with time zone, and one that takes time without time zone or timestamp without time zone. For brevity, these variants are not shown separately. Also, the + and * operators come in commutative pairs (for example both date + integer and integer + date); we show only one of each such pair.

Table 9-27. Date/Time Operators

OperatorExampleResult
+ date '2001-09-28' + integer '7'date '2001-10-05'
+ date '2001-09-28' + interval '1 hour'timestamp '2001-09-28 01:00:00'
+ date '2001-09-28' + time '03:00'timestamp '2001-09-28 03:00:00'
+ interval '1 day' + interval '1 hour'interval '1 day 01:00:00'
+ timestamp '2001-09-28 01:00' + interval '23 hours'timestamp '2001-09-29 00:00:00'
+ time '01:00' + interval '3 hours'time '04:00:00'
- - interval '23 hours'interval '-23:00:00'
- date '2001-10-01' - date '2001-09-28'integer '3' (days)
- date '2001-10-01' - integer '7'date '2001-09-24'
- date '2001-09-28' - interval '1 hour'timestamp '2001-09-27 23:00:00'
- time '05:00' - time '03:00'interval '02:00:00'
- time '05:00' - interval '2 hours'time '03:00:00'
- timestamp '2001-09-28 23:00' - interval '23 hours'timestamp '2001-09-28 00:00:00'
- interval '1 day' - interval '1 hour'interval '1 day -01:00:00'
- timestamp '2001-09-29 03:00' - timestamp '2001-09-27 12:00'interval '1 day 15:00:00'