This page was generated
January  28,  2016
4:08  AM
XQuery & XSLT Built-In & Modules Function Reference

Built-In: DurationDateTime

The duration, date, and time built-in functions are XQuery functions that operate on duration-, date-, and time-related values. They are defined in XQuery 1.0 and XPath 2.0 Functions and Operators.
Function Summary
fn:adjust-date-to-timezone Adjusts an xs:date value to a specific timezone, or to no timezone at all.
fn:adjust-dateTime-to-timezone Adjusts an xs:dateTime value to a specific timezone, or to no timezone at all.
fn:adjust-time-to-timezone Adjusts an xs:time value to a specific timezone, or to no timezone at all.
fn:day-from-date Returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.
fn:day-from-dateTime Returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.
fn:days-from-duration Returns an xs:integer representing the days component in the canonical lexical representation of the value of $arg.
fn:format-date Returns a formatted date value based on the picture argument.
fn:format-dateTime Returns a formatted dateTime value based on the picture argument.
fn:format-time Returns a formatted time value based on the picture argument.
fn:hours-from-dateTime Returns an xs:integer between 0 and 23, both inclusive, representing the hours component in the localized value of $arg.
fn:hours-from-duration Returns an xs:integer representing the hours component in the canonical lexical representation of the value of $arg.
fn:hours-from-time Returns an xs:integer between 0 and 23, both inclusive, representing the value of the hours component in the localized value of $arg.
fn:minutes-from-dateTime Returns an xs:integer value between 0 and 59, both inclusive, representing the minute component in the localized value of $arg.
fn:minutes-from-duration Returns an xs:integer representing the minutes component in the canonical lexical representation of the value of $arg.
fn:minutes-from-time Returns an xs:integer value between 0 to 59, both inclusive, representing the value of the minutes component in the localized value of $arg.
fn:month-from-date Returns an xs:integer between 1 and 12, both inclusive, representing the month component in the localized value of $arg.
fn:month-from-dateTime Returns an xs:integer between 1 and 12, both inclusive, representing the month component in the localized value of $arg.
fn:months-from-duration Returns an xs:integer representing the months component in the canonical lexical representation of the value of $arg.
fn:seconds-from-dateTime Returns an xs:decimal value between 0 and 60.999..., both inclusive representing the seconds and fractional seconds in the localized value of $arg.
fn:seconds-from-duration Returns an xs:decimal representing the seconds component in the canonical lexical representation of the value of $arg.
fn:seconds-from-time Returns an xs:decimal value between 0 and 60.999..., both inclusive, representing the seconds and fractional seconds in the localized value of $arg.
fn:subtract-dateTimes-yielding-dayTimeDuration [0.9-ml only, use the minus operator ( - ) instead] Returns the xdt:dayTimeDuration that corresponds to the difference between the normalized value of $srcval1 and the normalized value of $srcval2.
fn:subtract-dateTimes-yielding-yearMonthDuration [0.9-ml only, use the minus operator ( - ) instead] Returns the xdt:yearMonthDuration that corresponds to the difference between the normalized value of $srcval1 and the normalized value of $srcval2.
fn:timezone-from-date Returns the timezone component of $arg if any.
fn:timezone-from-dateTime Returns the timezone component of $arg if any.
fn:timezone-from-time Returns the timezone component of $arg if any.
fn:year-from-date Returns an xs:integer representing the year component in the localized value of $arg.
fn:year-from-dateTime Returns an xs:integer representing the year component in the localized value of $arg.
fn:years-from-duration Returns an xs:integer representing the years component in the canonical lexical representation of the value of $arg.
sql:dateadd Returns a specified date with the specified number interval (signed integer) added to a specified datepart of that date .
sql:datediff Returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.
sql:datepart Returns an integer that represents the specified datepart of the specified date.
xdmp:dayname-from-date Returns an xs:string representing the dayname value in the localized value of $arg.
xdmp:month-name-from-date Returns month name, calculated from the localized value of $arg.
xdmp:quarter-from-date Returns an xs:integer between 1 and 4, both inclusive, calculating the quarter component in the localized value of $arg.
xdmp:week-from-date Returns an xs:integer between 1 and 53, both inclusive, representing the week value in the localized value of $arg.
xdmp:weekday-from-date Returns an xs:integer between 1 and 7, both inclusive, representing the weekday value in the localized value of $arg.
xdmp:yearday-from-date Returns an xs:integer between 1 and 366, both inclusive, representing the yearday value in the localized value of $arg.
Function Detail
fn:adjust-date-to-timezone(
$arg as xs:date?,
[$timezone as xs:dayTimeDuration?]
)  as   xs:date?
Summary:

Adjusts an xs:date value to a specific timezone, or to no timezone at all. If $timezone is the empty sequence, returns an xs:date without a timezone. Otherwise, returns an xs:date with a timezone. For purposes of timezone adjustment, an xs:date is treated as an xs:dateTime with time 00:00:00.

If $timezone is not specified, then $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the result is the empty sequence.

A dynamic error is raised [err:FODT0003] if $timezone is less than -PT14H or greater than PT14H or if does not contain an integral number of minutes.

If $arg does not have a timezone component and $timezone is the empty sequence, then the result is $arg.

If $arg does not have a timezone component and $timezone is not the empty sequence, then the result is $arg with $timezone as the timezone component.

If $arg has a timezone component and $timezone is the empty sequence, then the result is the localized value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then:

Let $srcdt be an xs:dateTime value, with 00:00:00 for the time component and date and timezone components that are the same as the date and timezone components of $arg.

Let $r be the result of evaluating fn:adjust-dateTime-to-timezone($srcdt, $timezone)

The result of this function will be a date value that has date and timezone components that are the same as the date and timezone components of $r.


Parameters:
$arg : The date to adjust to the new timezone.
$timezone (optional): The new timezone for the date.

Example:
Assume the dynamic context provides an implicit timezone
of -05:00 (-PT5H0M).
let $tz := xs:dayTimeDuration("-PT10H")

fn:adjust-date-to-timezone(xs:date("2002-03-07"))
returns 2002-03-07-05:00.

fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00"))
returns 2002-03-07-05:00. $arg is converted to the xs:dateTime
"2002-03-07T00:00:00-07:00". This is adjusted to the implicit
timezone, giving "2002-03-07T02:00:00-05:00".

fn:adjust-date-to-timezone(
    xs:date("2002-03-07"), $tz)
returns 2002-03-07-10:00.

fn:adjust-date-to-timezone(
    xs:date("2002-03-07-07:00"), $tz)
returns 2002-03-06-10:00. $arg is converted to the xs:dateTime
"2002-03-07T00:00:00-07:00". This is adjusted to the given
timezone, giving "2002-03-06T21:00:00-10:00".

fn:adjust-date-to-timezone(xs:date("2002-03-07"), ())
returns 2002-03-07.

fn:adjust-date-to-timezone(
    xs:date("2002-03-07-07:00"), ())
returns 2002-03-07.

fn:adjust-dateTime-to-timezone(
$arg as xs:dateTime?,
[$timezone as xs:dayTimeDuration?]
)  as   xs:dateTime?
Summary:

Adjusts an xs:dateTime value to a specific timezone, or to no timezone at all. If $timezone is the empty sequence, returns an xs:dateTime without a timezone. Otherwise, returns an xs:dateTime with a timezone.

If $timezone is not specified, then $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the result is the empty sequence.

A dynamic error is raised [err:FODT0003] if $timezone is less than -PT14H or greater than PT14H or if does not contain an integral number of minutes.

If $arg does not have a timezone component and $timezone is the empty sequence, then the result is $arg.

If $arg does not have a timezone component and $timezone is not the empty sequence, then the result is $arg with $timezone as the timezone component.

If $arg has a timezone component and $timezone is the empty sequence, then the result is the localized value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then the result is an xs:dateTime value with a timezone component of $timezone that is equal to $arg.


Parameters:
$arg : The dateTime to adjust to the new timezone.
$timezone (optional): The new timezone for the dateTime.

Example:
Assume the dynamic context provides an implicit timezone
of -05:00 (-PT5H0M).
let $tz := xs:dayTimeDuration("-PT10H")

fn:adjust-dateTime-to-timezone(
    xs:dateTime("2002-03-07T10:00:00"))
returns 2002-03-07T10:00:00-05:00

fn:adjust-dateTime-to-timezone(
    xs:dateTime("2002-03-07T10:00:00-07:00"))
returns 2002-03-07T12:00:00-05:00

fn:adjust-dateTime-to-timezone(
     xs:dateTime("2002-03-07T10:00:00"), $tz)
returns 2002-03-07T10:00:00-10:00

fn:adjust-dateTime-to-timezone(
    xs:dateTime("2002-03-07T10:00:00-07:00"), $tz)
returns 2002-03-07T07:00:00-10:00

fn:adjust-dateTime-to-timezone(
    xs:dateTime("2002-03-07T10:00:00-07:00"),
    xs:dayTimeDuration("PT10H"))
returns 2002-03-08T03:00:00+10:00

fn:adjust-dateTime-to-timezone(
    xs:dateTime("2002-03-07T00:00:00+01:00"),
    xs:dayTimeDuration("-PT8H"))
returns 2002-03-06T15:00:00-08:00

fn:adjust-dateTime-to-timezone(
    xs:dateTime("2002-03-07T10:00:00"), ())
returns 2002-03-07T10:00:00

fn:adjust-dateTime-to-timezone(
    xs:dateTime("2002-03-07T10:00:00-07:00"), ())
returns 2002-03-07T10:00:00

fn:adjust-time-to-timezone(
$arg as xs:date?,
[$timezone as xs:dayTimeDuration?]
)  as   xs:integer?
Summary:

Adjusts an xs:time value to a specific timezone, or to no timezone at all. If $timezone is the empty sequence, returns an xs:time without a timezone. Otherwise, returns an xs:time with a timezone.

If $timezone is not specified, then $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the result is the empty sequence.

A dynamic error is raised [err:FODT0003] if $timezone is less than -PT14H or greater than PT14H or if does not contain an integral number of minutes.

If $arg does not have a timezone component and $timezone is the empty sequence, then the result is $arg.

If $arg does not have a timezone component and $timezone is not the empty sequence, then the result is $arg with $timezone as the timezone component.

If $arg has a timezone component and $timezone is the empty sequence, then the result is the localized value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then:

Let $srcdt be an xs:dateTime value, with an arbitrary date for the date component and time and timezone components that are the same as the time and timezone components of $arg.

Let $r be the result of evaluating fn:adjust-dateTime-to-timezone($srcdt, $timezone)

The result of this function will be a time value that has time and timezone components that are the same as the time and timezone components of $r.


Parameters:
$arg : The date to adjust to the new timezone.
$timezone (optional): The new timezone for the date.

Example:
Assume the dynamic context provides an implicit timezone
of -05:00 (-PT5H0M).
let $tz := xs:dayTimeDuration("-PT10H")

fn:adjust-time-to-timezone(xs:time("10:00:00"))
returns 10:00:00-05:00

fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"))
returns 12:00:00-05:00

fn:adjust-time-to-timezone(xs:time("10:00:00"), $tz)
returns 10:00:00-10:00

fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"), $tz)
returns 07:00:00-10:00

fn:adjust-time-to-timezone(xs:time("10:00:00"), ())
returns 10:00:00

fn:adjust-time-to-timezone(xs:time("10:00:00-07:00"), ())
returns 10:00:00

fn:adjust-time-to-timezone(
    xs:time("10:00:00-07:00"),
    xs:dayTimeDuration("PT10H"))
returns 03:00:00+10:00

fn:day-from-date(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose day component will be returned.

Example:
fn:day-from-date(xs:date("1999-05-31-05:00"))
returns 31
Example:
fn:day-from-date(xs:date("2000-01-01+05:00"))
returns 1

fn:day-from-dateTime(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The dateTime whose day component will be returned.

Example:
fn:day-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))
returns 31
Example:
fn:day-from-dateTime(
    xs:dateTime("1999-12-31T20:00:00-05:00"))
returns 31
Example:
fn:day-from-dateTime(
    fn:adjust-dateTime-to-timezone(
        xs:dateTime("1999-12-31T19:20:00-05:00"),
        xs:dayTimeDuration("PT0H")))
returns 1

fn:days-from-duration(
$arg as xs:duration?
)  as   xs:integer?
Summary:

Returns an xs:integer representing the days component in the canonical lexical representation of the value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The duration whose day component will be returned.

Example:
fn:days-from-duration(xs:duration("P3DT10H"))
returns 3
Example:
fn:days-from-duration(xs:duration("P3DT55H"))
returns 5

fn:format-date(
$value as xs:date,
$picture as xs:string,
[$language as xs:string],
[$calendar as xs:string],
[$country as xs:string]
)  as   xs:string
Summary:

Returns a formatted date value based on the picture argument. This is an XSLT function, and it is available in both XSLT and in XQuery 1.0-ml.

Parameters:
$value : The given date $value that needs to be formatted.
$picture : The desired string representation of the given date $value. The picture string is a sequence of characters, in which the characters represent variables such as, decimal-separator-sign, grouping-sign, zero-digit-sign, digit-sign, pattern-separator, percent sign and per-mille-sign. For details on the picture string, see http://www.w3.org/TR/xslt20/#date-picture-string.
$language (optional): The desired language for string representation of the date $value.
$calendar (optional): The only calendar supported at this point is "Gregorian" or "AD".
$country (optional): $country is used the specification to take into account country specific string representation.

Usage Notes:

Dates before October 15, 1582 (the start of the Gregorian calendar) will not return the correct date value.


Example:
   fn:format-date(fn:current-date(),
                 "[Y01]/[M01]/[D01]")

   fn:format-date(fn:current-date(),
                 "[Y01]/[M01]/[D01]","en","AD","US")
 

fn:format-dateTime(
$value as xs:dateTime,
$picture as xs:string,
[$language as xs:string],
[$calendar as xs:string],
[$country as xs:string]
)  as   xs:string
Summary:

Returns a formatted dateTime value based on the picture argument. This is an XSLT function, and it is available in both XSLT and in XQuery 1.0-ml.

Parameters:
$value : The given dateTime $value that needs to be formatted.
$picture : The desired string representation of the given dateTime $value. The picture string is a sequence of characters, in which the characters represent variables such as, decimal-separator-sign, grouping-sign, zero-digit-sign, digit-sign, pattern-separator, percent sign and per-mille-sign. For details on the picture string, see http://www.w3.org/TR/xslt20/#date-picture-string.
$language (optional): The desired language for string representation of the dateTime $value.
$calendar (optional): The only calendar supported at this point is "Gregorian" or "AD".
$country (optional): $country is used the specification to take into account country specific string representation.

Usage Notes:

Dates before October 15, 1582 (the start of the Gregorian calendar) will not return the correct dateTime value.

If the specified picture string includes a fractional second width that is seven or more decimal places, then the fractional seconds are truncated (not rounded) on the seventh and greater width.


Example:
   fn:format-dateTime(fn:current-dateTime(),
                 "[Y01]/[M01]/[D01] [H01]:[m01]:[s01]:[f01]")

   fn:format-dateTime(fn:current-dateTime(),
                 "[Y01]/[M01]/[D01] [H01]:[m01]:[s01]:[f01]","en","AD","US")
 

fn:format-time(
$value as time,
$picture as xs:string,
[$language as xs:string],
[$calendar as xs:string],
[$country as xs:string]
)  as   xs:string
Summary:

Returns a formatted time value based on the picture argument. This is an XSLT function, and it is available in both XSLT and in XQuery 1.0-ml.

Parameters:
$value : The given time $value that needs to be formatted.
$picture : The desired string representation of the given time $value. The picture string is a sequence of characters, in which the characters represent variables such as, decimal-separator-sign, grouping-sign, zero-digit-sign, digit-sign, pattern-separator, percent sign and per-mille-sign. For details on the picture string, see http://www.w3.org/TR/xslt20/#date-picture-string.
$language (optional): The desired language for string representation of the time $value.
$calendar (optional): The only calendar supported at this point is "Gregorian" or "AD".
$country (optional): $country is used the specification to take into account country specific string representation.

Usage Notes:

If the specified picture string includes a fractional second width that is seven or more decimal places, then the fractional seconds are truncated (not rounded) on the seventh and greater width.


Example:
   fn:format-time(fn:current-time(),
                 "[H01]:[m01]:[s01]:[f01]")

   fn:format-time(fn:current-time(),
                 "[H01]:[m01]:[s01]:[f01]","en","AD","US")
 

fn:hours-from-dateTime(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer between 0 and 23, both inclusive, representing the hours component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The dateTime whose hours component will be returned.

Example:
fn:hours-from-dateTime(
    xs:dateTime("1999-05-31T08:20:00-05:00"))
returns 8
Example:
fn:hours-from-dateTime(
    xs:dateTime("1999-12-31T21:20:00-05:00"))
returns 21
Example:
fn:hours-from-dateTime(
  fn:adjust-dateTime-to-timezone(
    xs:dateTime("1999-12-31T21:20:00-05:00"),
    xs:dayTimeDuration("PT0H"))) 
returns 2
Example:
fn:hours-from-dateTime(
    xs:dateTime("1999-12-31T12:00:00"))
returns 12

fn:hours-from-duration(
$arg as xs:duration?
)  as   xs:integer?
Summary:

Returns an xs:integer representing the hours component in the canonical lexical representation of the value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The duration whose hour component will be returned.

Example:
fn:hours-from-duration(xs:duration("P3DT10H"))
returns 10
Example:
fn:hours-from-duration(xs:duration("P3DT12H32M12S"))
returns 12
Example:
fn:hours-from-duration(xs:duration("PT123H"))
returns 3
Example:
fn:hours-from-duration(xs:duration("-P3DT10H"))
returns -10

fn:hours-from-time(
$arg as xs:time?
)  as   xs:integer?
Summary:

Returns an xs:integer between 0 and 23, both inclusive, representing the value of the hours component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The time whose hours component will be returned.

Example:
fn:hours-from-time(xs:time("11:23:00"))
returns 11
Example:
fn:hours-from-time(xs:time("21:23:00"))
returns 21
Example:
fn:hours-from-time(xs:time("01:23:00+05:00"))
returns 1
Example:
fn:hours-from-time(
    fn:adjust-time-to-timezone(
         xs:time("01:23:00+05:00"),
         xs:dayTimeDuration("PT0H")))
returns 20

fn:minutes-from-dateTime(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer value between 0 and 59, both inclusive, representing the minute component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The dateTime whose minutes component will be returned.

Example:
fn:minutes-from-dateTime(
    xs:dateTime("1999-05-31T13:20:00-05:00"))
returns 20
Example:
fn:minutes-from-dateTime(
    xs:dateTime("1999-05-31T13:30:00+05:30"))
returns 30

fn:minutes-from-duration(
$arg as xs:duration?
)  as   xs:integer?
Summary:

Returns an xs:integer representing the minutes component in the canonical lexical representation of the value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The duration whose minute component will be returned.

Example:
fn:minutes-from-duration(xs:duration("P3DT10H"))
returns 0
Example:
fn:minutes-from-duration(xs:duration("-P5DT12H30M"))
returns -30

fn:minutes-from-time(
$arg as xs:time?
)  as   xs:integer?
Summary:

Returns an xs:integer value between 0 to 59, both inclusive, representing the value of the minutes component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The time whose minutes component will be returned.

Example:
fn:minutes-from-time(xs:time("13:00:00Z"))
returns 0 

fn:month-from-date(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 12, both inclusive, representing the month component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose month component will be returned.

Example:
fn:month-from-date(xs:date("1999-05-31-05:00"))
returns 5 
Example:
fn:month-from-date(xs:date("2000-01-01+05:00"))
returns 1

fn:month-from-dateTime(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 12, both inclusive, representing the month component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The dateTime whose month component will be returned.

Example:
fn:month-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))
returns 5
Example:
fn:month-from-dateTime(xs:dateTime("1999-12-31T19:20:00-05:00"))
returns 12
Example:
fn:month-from-dateTime(
    fn:adjust-dateTime-to-timezone(
        xs:dateTime("1999-12-31T19:20:00-05:00"),
        xs:dayTimeDuration("PT0H")))
returns 1

fn:months-from-duration(
$arg as xs:duration?
)  as   xs:integer?
Summary:

Returns an xs:integer representing the months component in the canonical lexical representation of the value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The duration whose month component will be returned.

Example:
fn:months-from-duration(xs:duration("P20Y15M"))
returns 3
Example:
fn:months-from-duration(xs:duration("-P20Y18M"))
returns -6

fn:seconds-from-dateTime(
$arg as xs:dateTime?
)  as   xs:decimal?
Summary:

Returns an xs:decimal value between 0 and 60.999..., both inclusive representing the seconds and fractional seconds in the localized value of $arg. Note that the value can be greater than 60 seconds to accommodate occasional leap seconds used to keep human time synchronized with the rotation of the planet.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The dateTime whose seconds component will be returned.

Example:
fn:seconds-from-dateTime(
    xs:dateTime("1999-05-31T13:20:00-05:00"))
returns 0

fn:seconds-from-duration(
$arg as xs:duration?
)  as   xs:decimal?
Summary:

Returns an xs:decimal representing the seconds component in the canonical lexical representation of the value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The duration whose minute component will be returned.

Example:
fn:seconds-from-duration(xs:duration("P3DT10H12.5S"))
returns 12.5
Example:
fn:seconds-from-duration(xs:duration("-P256S"))
returns -16.0

fn:seconds-from-time(
$arg as xs:time?
)  as   xs:decimal?
Summary:

Returns an xs:decimal value between 0 and 60.999..., both inclusive, representing the seconds and fractional seconds in the localized value of $arg. Note that the value can be greater than 60 seconds to accommodate occasional leap seconds used to keep human time synchronized with the rotation of the planet.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The time whose seconds component will be returned.

Example:
fn:seconds-from-time(xs:time("13:20:10.5"))
returns 10.5

fn:subtract-dateTimes-yielding-dayTimeDuration(
$srcval1 as xs:dateTime,
$srcval1 as xs:dateTime
)  as   xdt:dayTimeDuration
Summary:

[0.9-ml only, use the minus operator ( - ) instead] Returns the xdt:dayTimeDuration that corresponds to the difference between the normalized value of $srcval1 and the normalized value of $srcval2. If either argument is the empty sequence, returns the empty sequence. If the normalized value of $srcval1 precedes in time the normalized value of $srcval2, then the returned value is a negative duration.


Parameters:
$srcval1 : The first xs:dateTime value.
$srcval1 : The second xs:dateTime value.

Example:
xquery version "0.9-ml"
fn:subtract-dateTimes-yielding-dayTimeDuration(
  fn:current-dateTime(),
  xs:dateTime("2000-01-11T12:01:00.000Z"))
=> the dayTimeDuration P3240DT14H49M46.37S, or
   whatever is correct for the current date

fn:subtract-dateTimes-yielding-yearMonthDuration(
$srcval1 as xs:dateTime,
$srcval1 as xs:dateTime
)  as   xdt:yearMonthDuration
Summary:

[0.9-ml only, use the minus operator ( - ) instead] Returns the xdt:yearMonthDuration that corresponds to the difference between the normalized value of $srcval1 and the normalized value of $srcval2. If either argument is the empty sequence, returns the empty sequence. If the normalized value of $srcval1 precedes in time the normalized value of $srcval2, the returned value is a negative duration.


Parameters:
$srcval1 : The first xs:dateTime value.
$srcval1 : The second xs:dateTime value.

Example:
xquery version "0.9-ml"
fn:subtract-dateTimes-yielding-yearMonthDuration(
  fn:current-dateTime(),
  xs:dateTime("2000-01-11T12:01:00.000Z"))
=> the yearMonthDuration P8Y10M, or whatever is
   correct for the current date

fn:timezone-from-date(
$arg as xs:dateTime?
)  as   xs:dayTimeDuration?
Summary:

Returns the timezone component of $arg if any. If $arg has a timezone component, then the result is an xs:dayTimeDuration that indicates deviation from UTC; its value may range from +14:00 to -14:00 hours, both inclusive. Otherwise, the result is the empty sequence.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose timezone component will be returned.

Example:
fn:timezone-from-date(xs:date("1999-05-31-05:00"))
returns the xs:dayTimeDuration whose value is -PT5H
Example:
fn:timezone-from-date(xs:date("2000-06-12Z"))
returns the xs:dayTimeDuration with value PT0H

fn:timezone-from-dateTime(
$arg as xs:dateTime?
)  as   xs:dayTimeDuration?
Summary:

Returns the timezone component of $arg if any. If $arg has a timezone component, then the result is an xs:dayTimeDuration that indicates deviation from UTC; its value may range from +14:00 to -14:00 hours, both inclusive. Otherwise, the result is the empty sequence.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The dateTime whose timezone component will be returned.

Example:
fn:timezone-from-dateTime(
    xs:dateTime("1999-05-31T13:20:00-05:00"))
returns the xs:dayTimeDuration whose value is -PT5H
Example:
fn:timezone-from-dateTime(
    xs:dateTime("2000-06-12T13:20:00Z"))
returns the xs:dayTimeDuration whose value is PT0S
Example:
fn:timezone-from-dateTime(
    xs:dateTime("2004-08-27T00:00:00"))
returns ()

fn:timezone-from-time(
$arg as xs:time?
)  as   xs:dayTimeDuration?
Summary:

Returns the timezone component of $arg if any. If $arg has a timezone component, then the result is an xs:dayTimeDuration that indicates deviation from UTC; its value may range from +14:00 to -14:00 hours, both inclusive. Otherwise, the result is the empty sequence.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The time whose timezone component will be returned.

Example:
fn:timezone-from-time(xs:time("13:20:00-05:00"))
returns xs:dayTimeDuration whose value is -PT5H
Example:
fn:timezone-from-time(xs:time("13:20:00"))
returns ()

fn:year-from-date(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer representing the year component in the localized value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose year component will be returned.

Example:
fn:year-from-date(xs:date("1999-05-31"))
returns 1999
Example:
fn:year-from-date(xs:date("2000-01-01+05:00"))
returns 2000

fn:year-from-dateTime(
$arg as xs:dateTime?
)  as   xs:integer?
Summary:

Returns an xs:integer representing the year component in the localized value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The dateTime whose year component will be returned.

Example:
fn:year-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))
returns 1999
Example:
fn:year-from-dateTime(xs:dateTime("1999-05-31T21:30:00-05:00"))
returns 1999
Example:
fn:year-from-dateTime(xs:dateTime("1999-12-31T19:20:00"))
returns 1999

fn:years-from-duration(
$arg as xs:duration?
)  as   xs:integer?
Summary:

Returns an xs:integer representing the years component in the canonical lexical representation of the value of $arg. The result may be negative.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The duration whose year component will be returned.

Example:
fn:years-from-duration(xs:duration("P20Y15M"))
returns 21
Example:
fn:years-from-duration(xs:duration("-P15M"))
returns -1

sql:dateadd(
$datepart as xs:string,
$number as xs:integer,
$date as item()
)  as   The return data type is the data type of the date argument
Summary:

Returns a specified date with the specified number interval (signed integer) added to a specified datepart of that date


Parameters:
$datepart : Is the part of date where the number will be added.The following table lists all valid datepart arguments.User-defined variable equivalents are not valid.

Options:

datepart parameter abbreviation includes:

"year","yyyy","yy"
The year part of the date
"quarter","qq","q"
The quarter part of the date
"month","mm","m"
The month part of the date
"dayofyear","dy","y"
The day of the year from the date
"day","dd","d"
The day of the month from the date
"week","wk","ww"
The week of the year from the date
"weekday","dw"
The day of the week from the date
"hour","hh"
The hour of the day from the date
"minute","mi","n"
The minute of the hour from the date
"second","ss","s"
The second of the minute from the date
"millisecond","ms"
The millisecond of the minute from the date
"microsecond","msc"
The microsecond of the minute from the date
"nanosecond","ns"
The nanosecond of the minute from the date
$number : This number will be added to the datepart of the given date.
$date : Is an expression that can be resolved to a time, date or datetime, value. date can be an expression, column expression, user-defined variable or string literal. startdate is subtracted from enddate.

Usage Notes:

This function is only available for use within SQL; it is not available directly from XQuery or XSLT.


Example:
 sql:dateadd('day',45, '2008-11-11T13:23:44.657')
returns   2008-12-26T13:23:44.657

sql:datediff(
$datepart as xs:string,
$startdate as item(),
$enddate as item()
)  as   xs:integer?
Summary:

Returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.


Parameters:
$datepart : Is the part of startdate and enddate that specifies the type of boundary crossed. The following table lists all valid datepart arguments. User-defined variable equivalents are not valid.

Options:

datepart parameter abbreviation includes:

"year","yyyy","yy"
The year part of the date
"quarter","qq","q"
The quarter part of the date
"month","mm","m"
The month part of the date
"dayofyear","dy","y"
The day of the year from the date
"day","dd","d"
The day of the month from the date
"week","wk","ww"
The week of the year from the date
"weekday","dw"
The day of the week from the date
"hour","hh"
The hour of the day from the date
"minute","mi","n"
The minute of the hour from the date
"second","ss","s"
The second of the minute from the date
"millisecond","ms"
The millisecond of the minute from the date
"microsecond","msc"
The microsecond of the minute from the date
"nanosecond","ns"
The nanosecond of the minute from the date
$startdate : Is an expression that can be resolved to a time, date, datetime or value. date can be an expression, column expression, user-defined variable or string literal. startdate is subtracted from enddate.
$enddate : Same as startdate.

Usage Notes:

This function is only available for use within SQL; it is not available directly from XQuery or XSLT.


Example:
select datediff('day','2008-06-05','2008-08-05')
returns -61
Example:
select datediff('day','2008-08-05','2008-06-05')
returns 61

sql:datepart(
$datepart as xs:string?,
$date as xs:genericDateTimeArg
)  as   xs:integer?
Summary:

Returns an integer that represents the specified datepart of the specified date.

If datepart or date is the empty sequence, the function returns the empty sequence.


Parameters:
$datepart : The part of date that to be returned.

Options:

datepart parameter abbreviation includes:

"year","yyyy","yy"
The year part of the date
"quarter","qq","q"
The quarter part of the date
"month","mm","m"
The month part of the date
"dayofyear","dy","y"
The day of the year from the date
"day","dd","d"
The day of the month from the date
"week","wk","ww"
The week of the year from the date
"weekday","dw"
The day of the week from the date
"hour","hh"
The hour of the day from the date
"minute","mi","n"
The minute of the hour from the date
"second","ss","s"
The second of the minute from the date
"millisecond","ms"
The millisecond of the minute from the date
"microsecond","msc"
The microsecond of the minute from the date
"nanosecond","ns"
The nanosecond of the minute from the date
"TZoffset","tz"
The timezone offset from the date
$date : Is an expression that can be resolved to a xs:date, xs:time, xs:dateTime. date can be an expression, column expression,user-defined variable, or string literal.

Usage Notes:

This function is only available for use within SQL; it is not available directly from XQuery or XSLT.


Example:
select datepart('yy','2007-10-30T12:15:32.1234567+05:10'))
returns 2007
Example:
select datepart("dayofyear",'2007-10-30T12:15:32.1234567+05:10'))
returns 303

xdmp:dayname-from-date(
$arg as xs:date?
)  as   xs:string?
Summary:

Returns an xs:string representing the dayname value in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose dayname value will be returned.

Example:
xdmp:dayname-from-date(xs:date("1997-07-20"))
returns sunday
Example:
xdmp:dayname-from-date(xs:date("2012-05-16"))
returns wednesday

xdmp:month-name-from-date(
$arg as xs:date?
)  as   xs:string?
Summary:

Returns month name, calculated from the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose month-name will be returned.

Example:
xdmp:month-name-from-date(xs:date("1999-05-31"))
returns May 
Example:
xdmp:month-name-from-date(xs:date("2000-01-01"))
returns January

xdmp:quarter-from-date(
$arg as xs:date?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 4, both inclusive, calculating the quarter component in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose quarter component will be returned.

Example:
xdmp:quarter-from-date(xs:date("1999-05-31"))
returns 2 
Example:
xdmp:quarter-from-date(xs:date("2000-01-01"))
returns 1

xdmp:week-from-date(
$arg as xs:date?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 53, both inclusive, representing the week value in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose weeks of the year will be returned.

Example:
xdmp:week-from-date(xs:date("2012-05-16"))
returns 20
Example:
xdmp:week-from-date(xs:date("2000-01-01"))
returns 1

xdmp:weekday-from-date(
$arg as xs:date?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 7, both inclusive, representing the weekday value in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose weekday value will be returned.

Example:
xdmp:weekday-from-date(xs:date("1997-07-16"))
returns 4
Example:
xdmp:weekday-from-date(xs:date("2012-05-16"))
returns 4

xdmp:yearday-from-date(
$arg as xs:date?
)  as   xs:integer?
Summary:

Returns an xs:integer between 1 and 366, both inclusive, representing the yearday value in the localized value of $arg.

If $arg is the empty sequence, returns the empty sequence.


Parameters:
$arg : The date whose days of the year will be returned.

Example:
xdmp:yearday-from-date(xs:date('1997-07-16'))
returns 196
Example:
xdmp:yearday-from-date(xs:date(2000-01-01'))
returns 1