Date/Time Arithmetic

Restriction: This topic applies to Windows environments only.

If a date-time value is the operand of addition, the other operand must be a duration. The rules for subtracting are different because a date-time value cannot be subtracted from a duration, and subtracting two date-time values differs from subtracting a duration from a date-time value. The rules for date-time arithmetic are shown in the following table.

Addition Rules

If one operand is a... ...the other operand must be a...
Date
  • Date Duration
  • Labeled Duration of years, months or days
Time
  • Time Duration
  • Labeled Duration of hours, minutes or seconds
Timestamp
  • Timestamp Duration
  • Labeled Duration of years, months, days, hours, minutes or seconds

Subtraction Rules

If the FIRST operand is a... ...the SECOND operand must be a...
Date
  • Date
  • Date Duration
  • String representation of a date
  • Labeled duration of years, months or days
Time
  • Time
  • Time Duration
  • String representation of a time
  • Labeled duration of hours, minutes or seconds
Timestamp
  • Timestamp
  • Timestamp Duration
  • Date Duration
  • Time Duration
  • String representation of a timestamp
  • Labeled duration of years, months, days, hours, minutes or seconds
If the SECOND operand is a... ...the FIRST operand must be a...
Date
  • Date
  • String representation of a date
Time
  • Time
  • String representation of a time
Timestamp
  • Timestamp
  • String representation of a timestamp

More: