xpath2 | durations, date and time functions

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Functions > Function Library Reference >

xpath2 | durations, date and time functions

XPath2 functions are available when either the XSLT2 or XQuery languages are selected.

 

The XPath 2 duration and date and time functions enable you to adjust dates and times for the timezone, extract particular components from date-time data, and subtract one date-time unit from another.

 

The 'Adjust-to-Timezone' functions

Each of these related functions takes a date, time, or dateTime as the first argument and adjusts the input by adding, removing, or modifying the timezone component depending on the value of the second argument.

 

The following situations are possible when the first argument contains no timezone (for example, the date 2009-01 or the time 14:00:00).

 

Timezone argument (the second argument of the function) is present: The result will contain the timezone specified in the second argument. The timezone in the second argument is added.
Timezone argument (the second argument of the function) is absent: The result will contain the implicit timezone, which is the system's timezone. The system's timezone is added.
Timezone argument (the second argument of the function) is empty: The result will contain no timezone.

 

The following situations are possible when the first argument contains a timezone (for example, the date 2009-01-01+01:00 or the time 14:00:00+01:00).

 

Timezone argument (the second argument of the function) is present: The result will contain the timezone specified in the second argument. The original timezone is replaced by the timezone in the second argument.
Timezone argument (the second argument of the function) is absent: The result will contain the implicit timezone, which is the system's timezone. The original timezone is replaced by the system's timezone.
Timezone argument (the second argument of the function) is empty: The result will contain no timezone.

 

The 'From' functions

Each of the 'From' functions extracts a particular component from: (i) date or time data, and (ii) duration data. The results are of the xs:decimal datatype.

 

As an example of extracting a component from date or time data, consider the day-from-date function (screenshot below).

FXdatesfrom

The input argument is a date (2009-01-01) of type xs:date. The day-from-date function extracts the day component of the date (1) as an xs:decimal datatype.

 

Extraction of time components from durations requires that the duration be specified either as xs:yearMonthDuration (for extracting years and months) or xs:dayTimeDuration (for extracting days, hours, minutes, and seconds). The result will be of type xs:decimal. The screenshot below shows a dayTimeDuration of P2DT0H being input to the days-from-duration function. The result is the xs:decimal 2.

 

FXdatesfromduration

 

The 'Subtract' functions

Each of the three subtraction functions enables you to subtract one time value from another and return a duration value. The three subtraction functions are: subtract-dates, subtract-times, subtract-dateTimes.

 

The screenshot below shows how the subtract-dates function is used to subtract two dates (2009-10-22 minus 2009-09-22). The result is the dayTimeDuration P30D.

FXdatessubtract


© 2019 Altova GmbH