Date, Time, and Duration Functions

Because FEEL does not support literal representation of date, time, or duration values, you must use a combination of built-in functions and string or number literals to express these values.

Built-in functions extract date, time, and duration data from strings or numbers. The following sections provide examples of common date and time operations using built-in functions:

Conversion Examples

Examples in this section demonstrate conversion of number or string literals into date, time, or duration data types.

Date and Time Data Type Examples

The following examples convert string literals to date or date-time values.

Example Description

date("2012-12-25")

Represents the date 2012-12-25 in the YYYY-MM-DD format.

time("23:59:00")

Represents the time 23:59:00 in the hh:mm:ss format.

time("23:59:00-08:00")

Represents the local time 23:59:00 in the hh:mm:ss format; the local time is 8 hours behind UTC.

date and time("2012-12-25T11:00:00")

Represents the date 2012-12-25 and time 11:00:00 in YYYY-MM-DD and hh:mm:ss formats, respectively.

date and time("2012-12-25T11:00:00Z")

Represents the date 2012-12-25 and time 11:00:00 in YYYY-MM-DD and hh:mm:ss formats, respectively; "Z" represents UTC time.

Duration Data Type Examples

A few conversion examples using the duration function are listed in the following table.

Example Description

duration("P1DT12H30M")

Represents a duration of 1 day, 12 hours, and 30 minutes.

duration("-P120D")

Represents a duration of minus 120 days.

duration("PT2000H")

Represents a duration of 2000 hours.

duration("P1Y2M3DT10H30M")

Represents a duration of 1 year, 2 months, 3 days, 10 hours, and 30 minutes.

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.

Comparison Operation Examples

Examples in this section demonstrate comparison operations that can be performed on date or time data types.

Operator Example Result Description

>

date("2012-12-25") > date("2015-12-25")

false

Determines if Date A occurs after Date B.

>

((date("2015-12-25") - date("2015-11-25")) > duration( "P1Y" )

false

Determines if Duration A is greater than Duration B.