MENU
Datetime Functions
Datetime functions extract components from durations, dates, times, and dateTimes; adjust timezones; format values for display; and read the current date, time, and implicit timezone. See Data Types for the underlying xs:date, xs:time, xs:dateTime, and duration types.| years-from-duration(xs:yearMonthDuration("P20Y15M")) | 21 |
| months-from-duration(xs:yearMonthDuration("-P20Y18M")) | -6 |
| days-from-duration(xs:dayTimeDuration("P3DT55H")) | 5 |
| hours-from-duration(xs:dayTimeDuration("P3DT12H32M12S")) | 12 |
| minutes-from-duration(xs:dayTimeDuration("P3DT10H")) | 0 |
| seconds-from-duration(xs:dayTimeDuration("-PT256S")) | -16 |
| dateTime(xs:date("1999-12-31"), xs:time("12:00:00")) | xs:dateTime('1999-12-31T12:00:00') |
| year-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) | 1999 |
| month-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) | 5 |
| day-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) | 31 |
| hours-from-dateTime(xs:dateTime("1999-05-31T08:20:00-05:00")) | 8 |
| minutes-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) | 20 |
| seconds-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) | 0 |
| timezone-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) | xs:dayTimeDuration("-PT5H") |
| year-from-date(xs:date("1999-05-31")) | 1999 |
| month-from-date(xs:date("1999-05-31-05:00")) | 5 |
| day-from-date(xs:date("1999-05-31-05:00")) | 31 |
| timezone-from-date(xs:date("1999-05-31-05:00")) | xs:dayTimeDuration("-PT5H") |
| hours-from-time(xs:time("11:23:00")) | 11 |
| minutes-from-time(xs:time("13:00:00Z")) | 0 |
| seconds-from-time(xs:time("13:20:10.5")) | 10.5 |
| timezone-from-time(xs:time("13:20:00Z")) | xs:dayTimeDuration('PT0S') |
| adjust-dateTime-to-timezone(xs:dateTime('2002-03-07T00:00:00+01:00'), xs:dayTimeDuration("-PT8H")) | xs:dateTime('2002-03-06T15:00:00-08:00') |
| adjust-date-to-timezone(xs:date("2002-03-07-07:00"), xs:dayTimeDuration("-PT10H")) | xs:date("2002-03-06-10:00") |
| adjust-time-to-timezone(xs:time("10:00:00-07:00"), xs:dayTimeDuration("-PT10H")) | xs:time("07:00:00-10:00") |
| format-date(xs:date('2002-12-31'), "[MNn] [D], [Y]", "en", (), ()) | December 31, 2002 |
| format-time(xs:time('15:58:45'), "[h]:[m01]:[s01] [Pn]", "en", (), ()) | 3:58:45 pm |
| format-dateTime(xs:dateTime("2002-12-31T15:58:45"), "[M01]/[D01]/[Y0001] at [H01]:[m01]:[s01]") | 12/31/2002 at 15:58:45 |
| current-dateTime() | xs:dateTimeStamp('2014-09-06T07:30:58.767') |
| current-date() | xs:date('2014-09-06') |
| current-time() | xs:time('07:31:54.574') |
| implicit-timezone() | xs:dayTimeDuration('PT8H') |
| default-collation() | http://www.w3.org/2005/xpath-functions/collation/codepoint |
The results of current-dateTime(), current-date(), current-time(), implicit-timezone(), and default-collation() depend on the evaluating processor's clock, locale, and configuration; the values above are examples captured from one such processor, not fixed constants.
ch03-datetime-functions.xpath.txt:
format-date(xs:date('2002-12-31'), "[MNn] [D], [Y]", "en", (), ())December 31, 2002