days-from-duration function

The fn:days-from-duration function returns the days component of a duration.

Syntax

Read syntax diagramSkip visual syntax diagramfn:days-from-duration( duration-value)
duration-value
The duration value from which the days component is to be extracted.

duration-value is an empty sequence, or is a value that has one of the following types: xdt:dayTimeDuration, xs:duration, or xdt:yearMonthDuration.

Returned value

The return value depends on the type of duration-value:

  • If duration-value is of type xdt:dayTimeDuration or is of type xs:duration, the returned value is of type xs:integer, and is the days component of duration-value cast as xdt:dayTimeDuration. The returned value is negative if duration-value is negative.
  • If duration-value is of type xdt:yearMonthDuration, the returned value is 0.

  • If duration-value is an empty sequence, the returned value is an empty sequence.

The days component of duration-value cast as xdt:dayTimeDuration is the integer number of days computed as (S idiv 86400). The value S is the total number of seconds of duration-value cast as xdt:dayTimeDuration to remove the years and months components.

Examples

This function returns the days component of the duration -10 days and 0 hours.

fn:days-from-duration(xdt:dayTimeDuration("-P10DT00H"))

The returned value is -10.

This function returns the days component of the duration 3 days and 55 hours.

fn:days-from-duration(xdt:dayTimeDuration("P3DT55H"))

The returned value is 5. When calculating the total number of days in the duration, 55 hours is converted to 2 days and 7 hours. The duration is equal to P5D7H which has a days component of 5 days.