home contribute faq download

FunctX XQuery Functions

functx:date

Construct a date from a year, month and day

Google
Webxqueryfunctions.com

Description

The functx:date function constructs an xs:date value from arguments representing the year, month and day. The arguments can have any type that can be cast to xs:integer. If the combination does not result in a valid date (e.g. the day is 32 or the month is 13), an error is raised.

Arguments and Return Type

NameTypeDescription
$year xs:anyAtomicType the year
$month xs:anyAtomicType the month
$day xs:anyAtomicType the day
return value xs:date

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:date 
  ( $year as xs:anyAtomicType ,
    $month as xs:anyAtomicType ,
    $day as xs:anyAtomicType )  as xs:date {
       
   xs:date(
     concat(
       functx:pad-integer-to-length(xs:integer($year),4),'-',
       functx:pad-integer-to-length(xs:integer($month),2),'-',
       functx:pad-integer-to-length(xs:integer($day),2)))
 } ;
XQuery Syntax for July 2004 - November 2005 (CR):
declare namespace functx = "http://www.functx.com"; 
declare function functx:date 
  ( $year as xdt:anyAtomicType ,
    $month as xdt:anyAtomicType ,
    $day as xdt:anyAtomicType )  as xs:date {
       
   xs:date(
     concat(
       functx:pad-integer-to-length(xs:integer($year),4),'-',
       functx:pad-integer-to-length(xs:integer($month),2),'-',
       functx:pad-integer-to-length(xs:integer($day),2)))
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function date 
  ( $year as xdt:anyAtomicType ,
    $month as xdt:anyAtomicType ,
    $day as xdt:anyAtomicType )  as xs:date {
       
   xs:date(
     fn:concat(
       functx:pad-integer-to-length(xs:integer($year),4),'-',
       functx:pad-integer-to-length(xs:integer($month),2),'-',
       functx:pad-integer-to-length(xs:integer($day),2)))
 }

Examples

XQuery ExampleResults
functx:date(2006,6,12)
2006-06-12
functx:date('2006','06','12')
2006-06-12

Depends On

functx:pad-integer-to-lengthPads an integer to a desired length by adding leading zeros

See Also

functx:timeConstruct a time from an hour, minute and second

History

Published OnLast UpdatedContributor(s)
2006-08-222007-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