Skip to content
Date & Time Functions

Date & Time Functions

Current Date/Time

Function Returns
current-date() Current date as xs:date
current-dateTime() Current date and time as xs:dateTime
current-time() Current time as xs:time
implicit-timezone() System timezone as xs:dayTimeDuration

Constructors

Function Description
xs:date("2024-01-15") Construct date
xs:dateTime("2024-01-15T10:30:00") Construct dateTime
xs:time("10:30:00") Construct time (supports Z suffix)
xs:duration("P1Y2M3DT4H5M6S") Construct duration
xs:dayTimeDuration("P3DT4H") Day/time duration (extracts day/time parts)
xs:yearMonthDuration("P1Y6M") Year/month duration (extracts year/month parts)
dateTime($date, $time) Combine date and time
xs:gYear("2024") Year only
xs:gMonth("--03") Month only
xs:gDay("---15") Day only
xs:gYearMonth("2024-03") Year and month
xs:gMonthDay("--03-15") Month and day

Formatting

format-date / format-dateTime / format-time

format-date($value, $picture, $language?, $calendar?, $place?)

The picture string uses component specifiers in brackets:

Specifier Component Example
[Y] Year 2024
[Y01] Year, 2 digits 24
[M] Month number 3
[M01] Month, zero-padded 03
[MNn] Month name March
[D] Day of month 15
[D01] Day, zero-padded 15
[d] Day of year 74
[F] Day of week name Friday
[H] Hour (0-23) 10
[h] Hour (1-12) 10
[m] Minute 30
[s] Second 45
[f] Fractional seconds 123
[Z] Timezone Z or +05:30
[P] AM/PM a.m.
[YI] Year in Roman MMXXIV
[MI] Month in Roman III
[Y1o] Year with ordinal 2024th
[E] Era (AD/BC) AD
[C] Calendar ISO

Width modifiers: [M,3-3] (exactly 3 chars), [f,1-3] (1-3 fractional digits).

format-date(xs:date("2024-03-15"), "[D] [MNn] [Y]")
(: "15 March 2024" :)

format-dateTime(xs:dateTime("2024-03-15T10:30:00"), "[H]:[m] on [D]/[M01]/[Y]")
(: "10:30 on 15/03/2024" :)

parse-ietf-date

parse-ietf-date($value) — Parse RFC 2822 / RFC 850 date strings.

parse-ietf-date("Wed, 20 Aug 2014 19:36:01 GMT")

Duration Arithmetic

Durations support addition, subtraction, multiplication, and division:

xs:dayTimeDuration("P2D") + xs:dayTimeDuration("PT12H")    (: P2DT12H :)
xs:yearMonthDuration("P1Y") * 3                             (: P3Y :)
xs:date("2024-01-15") + xs:dayTimeDuration("P30D")          (: 2024-02-14 :)
xs:date("2024-03-01") - xs:date("2024-01-01")               (: P60D :)

Component Extraction

Function Argument Returns
year-from-date xs:date xs:integer
month-from-date xs:date xs:integer
day-from-date xs:date xs:integer
hours-from-dateTime xs:dateTime xs:integer
minutes-from-time xs:time xs:integer
seconds-from-time xs:time xs:decimal
years-from-duration xs:duration xs:integer
days-from-duration xs:duration xs:integer
(and all other component-extraction functions)

Timezone Adjustment

Function Description
adjust-date-to-timezone($date, $tz?) Adjust date timezone
adjust-dateTime-to-timezone($dt, $tz?) Adjust dateTime timezone
adjust-time-to-timezone($time, $tz?) Adjust time timezone
timezone-from-date($date) Extract timezone
timezone-from-dateTime($dt) Extract timezone
timezone-from-time($time) Extract timezone