Arithmetic Operation Examples
Examples in this section demonstrate arithmetic operations that can be performed on date, time, or duration data types.
Operator | Example | Result | Description |
---|---|---|---|
(+) |
date("2016-12-25") + duration("P3Y2M6D") |
date("2020-03-02") |
Returns the date 3 years 2 months and 6 days after 2016-12-25 |
(+) |
date and time("2016-12-25T12:30:00Z") + duration("P1Y2M3DT10H30M") |
date and time("2018-02-28T23:00:00Z") |
Returns the date and time 1 year 2 months 3 days and 10 hours 30 minutes after the date 2016-12-25 and time 12:30:00 |
(+) |
date("2016-12-25") + duration("-P3Y2M6D") |
date("2013-10-19") |
Returns the date 3 years 2 months and 6 days before 2016-12-25 |
(-) |
date("2015-12-25") - date("2012-12-25") |
duration("P1095DT0H0M0S") |
Returns a duration indicating number of days and time |
(-) |
date and time("2012-12-25T12:00:00") - date and time("2015-12-25T11:12:00") |
duration("-P1094DT23H12M0S") |
Returns a duration indicating number of days and time |
(-) |
date and time("2012-12-25T12:00:00-08:00") - date and time("2015-12-25T11:12:00Z") |
duration("-P1094DT15H12M0S") |
Returns a duration indicating the number of days and time between date and time of two different time zones. |
(-) |
date("2016-12-25") - duration("P3Y2M6D") |
date("2013-10-19") |
Returns the date 3 years 2 months and 6 days before 2016-12-25 |
(/) |
(date("2015-12-25") - date("2012-12-25"))/duration( "P1D" ) |
1095 |
Returns the number of days between two dates |
(/) |
(date and time("2015-12-25T17:00:00") - date and time("2015-12-25T09:12:00"))/duration( "PT1H" ) |
7.8 |
Returns the number of hours between two date and time values |
(/) |
(date("2015-12-25") - date("2015-12-24"))/duration( "P1Y" ) |
0.0027397260273972603 |
Returns the number of years between two dates |
None |
years and months duration(date("2012-12-23") , date("2015-12-25")) |
duration("-P3Y0M") |
Returns the years and months duration between two dates |