8.4.1. DATEADD()

Available in

DSQL, PSQL

Changed in

2.5

Syntax

  1. DATEADD (<args>)
  2. <args> ::=
  3. <amount> <unit> TO <datetime>
  4. | <unit>, <amount>, <datetime>
  5. <amount> ::= an integer expression (negative to subtract)
  6. <unit> ::=
  7. YEAR | MONTH | WEEK | DAY
  8. | HOUR | MINUTE | SECOND | MILLISECOND
  9. <datetime> ::= a DATE, TIME or TIMESTAMP expression
Table 141. DATEADD Function Parameters
ParameterDescription

amount

An integer expression of the SMALLINT, INTEGER or BIGINT type. A negative value is subtracted

unit

Date/time unit

datetime

An expression of the DATE, TIME or TIMESTAMP type

Result type

DATE, TIME or TIMESTAMP

Description

Adds the specified number of years, months, weeks, days, hours, minutes, seconds or milliseconds to a date/time value. (The WEEK unit is new in 2.5.)

  • The result type is determined by the third argument.

  • With TIMESTAMP and DATE arguments, all units can be used. (Prior to Firebird 2.5, units smaller than DAY were disallowed for DATEs.)

  • With TIME arguments, only HOUR, MINUTE, SECOND and MILLISECOND can be used.

Examples

  1. dateadd (28 day to current_date)
  2. dateadd (-6 hour to current_time)
  3. dateadd (month, 9, DateOfConception)
  4. dateadd (-38 week to DateOfBirth)
  5. dateadd (minute, 90, time 'now')
  6. dateadd (? year to date '11-Sep-1973')

See also

DATEDIFF(), Operations Using Date and Time Values