home contribute faq download

FunctX XQuery Functions

functx:mmddyyyy-to-date

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

Google
Webxqueryfunctions.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.
XQuery Syntax for July 2004 - January 2007 (1.0):
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'))
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function mmddyyyy-to-date 
  ( $dateString as xs:string? )  as xs:date? {
       
   if (fn:empty($dateString))
   then ()
   else if (fn:not(fn:matches($dateString,
                        '^\D*(\d{2})\D*(\d{2})\D*(\d{4})\D*$')))
   then fn:error(xs:QName('functx:Invalid_Date_Format'))
   else xs:date(fn: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
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley