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