home contribute faq download

FunctX XQuery Functions

functx:days-in-month

Number of days in the month

Google
Webdatypic.com

Description

The functx:days-in-month function returns the number of days in the month of $date as an integer.

The $date argument must be castable to xs:date, meaning that it must have the type xs:date or xs:dateTime, or be an xs:string or untyped value of the form YYYY-MM-DD.

Arguments and Return Type

NameTypeDescription
$date xs:anyAtomicType? the date
return value xs:integer?

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:days-in-month
  ( $date as xs:anyAtomicType? )  as xs:integer? {

   if (month-from-date(xs:date($date)) = 2 and
       functx:is-leap-year($date))
   then 29
   else
   (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
    [month-from-date(xs:date($date))]
 } ;

Examples

XQuery ExampleResults
functx:days-in-month(xs:date('2004-01-23'))
31
functx:days-in-month(
     xs:dateTime('2004-02-15T12:00:13'))
29
functx:days-in-month('2005-02-15')
28

Depends On

functx:is-leap-yearWhether a date falls in a leap year

See Also

functx:last-day-of-monthThe last day of the month of a date

History

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

Recommended Reading:

XQuery