saxon:parse-dateTime

Interprets a string representing a date and/or time in a user-defined format.

parse-dateTime($input as xs:string?, $format as xs:string) ➔ union(xs:dateTime, xs:date, xs:time, xs:gYear, xs:gYearMonth, xs:gMonth, xs:gMonthDay, xs:gDay)?

Arguments

 

$input

xs:string?

The input date/time

 

$format

xs:string

The format used to parse the date and time

Result

union(xs:dateTime, xs:date, xs:time, xs:gYear, xs:gYearMonth, xs:gMonth, xs:gMonthDay, xs:gDay)?

Namespace

http://saxon.sf.net/

Saxon availability

Requires Saxon-PE or Saxon-EE. Implemented since Saxon 10. Available for Java and C/C++ only (not .NET).

Notes on the Saxon implementation

Available since Saxon 10. Not available in SaxonCS.

Details

If the $input argument is an empty sequence, the result is an empty sequence.

The $format argument is a pattern representing the format of the date/time supplied in the $input argument. The pattern follows the rules of the Java DateTimeFormatter class. Here are some simple examples:

$input $format Result
9/23/2018 M/d/yyyy xs:date('2018-09-23')
23/9/2018 d/M/yyyy xs:date('2018-09-23')
10:14 Sep 23, 2012 HH:mm MMM dd, yyyy xs:dateTime('2012-09-23T10:14:00')
2018-03-31T14:20Z yyyy-MM-dd'T'HH:mmX xs:dateTime('2018-03-31T14:20:00Z')
8.42 h.mm xs:time('08:42:00')
2018-03-31T14:20 yyyy-MM-dd'T'HH:mm xs:dateTime('2018-03-31T14:20:00')

The locale used for parsing names of months is the system default locale.

Parsing is case-independent and is "smart" in the terminology of Java's ResolverStyle.

A dynamic error is raised if the pattern is invalid, or if the input cannot be parsed according to the rules of the pattern.

The return type depends on the components actually present in the supplied value, and is the first of the following that apply:

  • If year, month, day, hour, and minute are all present, then xs:dateTime (the seconds value defaults to zero).
  • If year, month, day are all present, then xs:date.
  • If hour and minute are both present, then xs:time (the seconds value defaults to zero).
  • If year and month are both present, then xs:gYearMonth.
  • If year is present, then xs:gYear.
  • If month and day are both present, then xs:gMonthDay.
  • If month is present, then xs:gMonth.
  • Otherwise, empty sequence.

If no timezone offset is specified, the result will have no timezone component.