xf:yearMonthDuration

Converts $string-var (a string in the yearMonthDuration format) to the yearMonthDuration data type.

If $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xf:yearMonthDuration(xs:string $string-var) —> xf:yearMonthDuration

Arguments

Data Type
Argument
Description

xs:string

$string-var

Represents a string with the duration specified with one of the following formats:

  • PyYmM
  • -PyYmM

Note: Either one or both of the following substrings: yY or mM must be specified. For example, the following are valid durations: P10Y, -P11M, or P6Y4M.

-

Duration is a negative amount of time.

Note: If - is not specified, duration is a positive amount of time.

P

The start of a duration string. The P must always be specified.

yY

y—number of years in the duration.

y—number of years in the duration.

mM

m—number of months in the duration.

M—months are specified in the duration.

Returns

Returns a duration of time as a yearMonthDuration value.

Examples

yearMonthDuration with Year and Month

Invoking yearMonthDuration("P1Y2M") returns a yearMonthDuration value corresponding to 1 year and 2 months, as shown in the following example query:

let $mydur := xf:yearMonthDuration("P1Y2M")
return
<components>
	<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
	<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</components> 

The preceding query, generates the following XML result:

<components>
	<years>1</years>
	<months>2</months>
</components> 

yearMonthDuration with Year

Invoking yearMonthDuration("P9Y") returns a yearMonthDuration value corresponding to 9 years, as shown in the following example query:

let $mydur := xf:yearMonthDuration("P9Y")
return
<components>
	<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
	<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</components> 

The preceding query, generates the following XML result:

<components>
	<years>9</years>
	<months>0</months>
</components> 

yearMonthDuration with Negative Month

Invoking yearMonthDuration("-P10M") returns a yearMonthDuration value corresponding to a negative 10 months, as shown in the following example query:

let $mydur := xf:yearMonthDuration("-P10M")
return
<components>
	<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
	<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</components> 

The preceding query, generates the following XML result:

<components>
	<years>0</years>
	<months>-10</months>
</components> 

Related Topics

W3C yearMonthDuration data type description.