Loading TOC...

MarkLogic 10 Product Documentation
xdmp:parse-dateTime

xdmp:parse-dateTime(
   $picture as xs:string,
   $value as xs:string,
   [$language as xs:string?],
   [$calendar as xs:string?],
   [$country as xs:string?]
) as xs:dateTime

Summary

Parses a string containing date, time or dateTime using the supplied picture argument and returns a dateTime value. While this function is closely related to other XSLT functions, it is available in XSLT as well as in all XQuery dialects and in Server-Side JavaScript.

Parameters
picture The desired string representation of the given $value. The picture string is a sequence of characters, in which the characters represent variables such as, decimal-separator-sign, grouping-sign, zero-digit-sign, digit-sign, pattern-separator, percent sign and per-mille-sign. For details on the picture string, see http://www.w3.org/TR/xslt20/#date-picture-string. This follows the specification of picture string in the W3C XSLT 2.0 specification for the fn:format-dateTime function.

   Symbol         Description
  -----------------------------------
     'Y'        year(absolute value)
     'M'        month in year
     'D'        day in month
     'd'        day in year
     'F'        day of week
     'W'        week in year
     'w'        week in month
     'H'        hour in day
     'h'        hour in half-day
     'P'        am/pm marker
     'm'        minute in hour
     's'        second in minute
     'f'        fractional seconds
     'Z'        timezone as a time offset from UTC
                for example PST
     'z'        timezone as an offset using GMT,
                for example GMT+1
value The given string $value representing the dateTime value that needs to be formatted.
language The language used in string representation of the date, time or dateTime value.
calendar This argument is reserved for future use. The only calendar supported at this point is "Gregorian" or "AD".
country $country is used to take into account if there any country specific interpretation of the string while converting it into dateTime value.

Usage Notes

Dates before October 15, 1582 (the start of the Gregorian calendar) will not return the correct dateTime value.

The xdmp:parse-dateTime function will not parse all dates; if it does not parse a date, it can throw the XDMP-PATTERNVALUEMISMATCH exception. To help normalize the dates so they can be parsed, you can try using the XSLT functions defined in the following stylesheet:

<marklogic-dir>/Modules/MarkLogic/appservices/utils/normalize-dates.xsl

In particular xdmp:parse-dateTime does not support parsing names of days or months.

Example

   xdmp:parse-dateTime("[Y0001]-[M01]-[D01]T[h01]:[m01]:[s01].[f1][Z]",
		   "2014-01-06T17:13:50.873594-08:00")
   =>
   2014-01-06T17:13:50.874-08:00
 

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.