home contribute faq download

FunctX XQuery Functions

functx:add-months

Adds months to a date

Google
Webxqueryfunctions.com

Description

The functx:add-months function adds a specified number of months to a date. 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
$months xs:integer the number of months to add
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:add-months 
  ( $date as xs:anyAtomicType? ,
    $months as xs:integer )  as xs:date? {
       
   xs:date($date) + functx:yearMonthDuration(0,$months)
 } ;
XQuery Syntax for July 2004 - November 2005 (CR):
declare namespace functx = "http://www.functx.com"; 
declare function functx:add-months 
  ( $date as xdt:anyAtomicType? ,
    $months as xs:integer )  as xs:date? {
       
   xs:date($date) + functx:yearMonthDuration(0,$months)
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function add-months 
  ( $date as xdt:anyAtomicType? ,
    $months as xs:integer )  as xs:date? {
       
   xs:date($date) + functx:yearMonthDuration(0,$months)
 }

Examples

XQuery ExampleResults
functx:add-months(xs:date('2004-01-23'),1)
2004-02-23
functx:add-months(
     xs:dateTime('2005-12-31T12:00:13'),2)
2006-02-28
functx:add-months('2005-12-31',-3)
2005-09-30

Depends On

functx:yearMonthDurationConstruct a yearMonthDuration from a number of years and months

See Also

functx:next-dayThe next day

History

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