home contribute faq download

FunctX XQuery Functions

functx:mmddyyyy-to-date

Converts a string with format MMDDYYYY (with any delimiters) to a date

Google
Webdatypic.com

Description

The functx:mmddyyyy-to-date function converts $dateString into a valid xs:date value. The order of the digits in $dateString must be MMDDYYYY, but it can contain any (or no) delimiters between the digits.

Arguments and Return Type

NameTypeDescription
$dateString xs:string? the MMDDYYYY string
return value xs:date?

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:mmddyyyy-to-date
  ( $dateString as xs:string? )  as xs:date? {

   if (empty($dateString))
   then ()
   else if (not(matches($dateString,
                        '^\D*(\d{2})\D*(\d{2})\D*(\d{4})\D*$')))
   then error(xs:QName('functx:Invalid_Date_Format'))
   else xs:date(replace($dateString,
                        '^\D*(\d{2})\D*(\d{2})\D*(\d{4})\D*$',
                        '$3-$1-$2'))
 } ;

Examples

XQuery ExampleResults
functx:mmddyyyy-to-date('12-15-2004')
2004-12-15
functx:mmddyyyy-to-date('12152004')
2004-12-15
functx:mmddyyyy-to-date('12/15/2004')
2004-12-15

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery