XQuery Reference

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

XQuery Duration Functions Reference

This chapter provides descriptions of the XQuery duration functions available in the mapper functionality of WebLogic Workshop. You use the mapper functionality to generate queries and to edit these queries to add invocations to these provided XQuery functions. To learn more, see Invoking Functions or Operators in a Query.

In addition to the XQuery functions and operators available in the mapper functionality, a larger set functions and operators is provided. You can manually add invocations to these functions and operators to queries in the Source View of the mapper functionality. For a list of these additional functions and operators, see the XQuery 1.0 and XPath 2.0 Functions and Operators - W3C Working Draft 16 August 2002 available from the W3C Web site at the following URL:

http://www.w3.org/TR/2002/WD-xquery-operators-20020816

This section lists the duration functions available from the mapper functionality:

 


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

Table 12-1 Arguments
Data Type
Argument
Description
xf: 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.

 


xf: dayTimeDuration

Converts $string-var (a string in the day TimeDuration format) to the dayTimeDuration 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

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

Table 12-2 Arguments
Data Type
Argument
Description
xs:string
$string-var
Represents a string with the duration specified with one of the following formats:
  • dDThHiMsS
  • -dDThHiMsS
Note: Specifying the number days, hours, minutes, or seconds is optional—any of the substrings: dD, hH, iM, or sS do not have to be specified. For example, the following are valid durations: P10Y, P1D, -P11M, -P10Y7D, P2YT5H, or P6YT5H10S.
-
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.
dD
d—number of days in the duration.
D—days are specified in the duration.
T
The start of the time part of the duration string. The T must be specified if any minutes, hours, or seconds (hH, iM, or sS) are specified.
hH
h—number of hours in the duration.
H—years are specified in the duration.
iM
i—number of minutes in the duration.
M—minutes are specified in the duration.
sS
s—number of seconds in the duration.
S—seconds are specified in the duration.

Returns

Returns a duration of time as a dayTimeDuration value.

Examples
dayTimeDuration with All Components

Invoking dayTimeDuration("P4DT9H8M20S") returns a dayTimeDuration value corresponding to 4 days, 9 hours, 8 minutes, and 20 seconds, as shown in the following example query:

let $mydur := xf:dayTimeDuration("P4DT9H8M20S")

return

<components>

<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>

<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>

<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>

<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>

</components>

The preceding query, generates the following XML result:

<components>

<days>4</days>

<hours>9</hours>

<minutes>8</minutes>

<seconds>20</seconds>

</components>

dayTimeDuration with Just Hours and Seconds

Invoking dayTimeDuration("PT2H20S") returns a dayTimeDuration value corresponding to 2 hours and 20 seconds, as shown in the following example query:

let $mydur := xf:dayTimeDuration("PT2H20S")

return

<components>

<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>

<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>

<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>

<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>

</components>

The preceding query, generates the following XML result:

<components>

<days>0</days>

<hours>2</hours>

<minutes>0</minutes>

<seconds>20</seconds>

</components>

dayTimeDuration with Just Negative Days

Invoking dayTimeDuration("-P10D") returns a dayTimeDuration value corresponding to negative 10 days, as shown in the following example query:

let $mydur := xf:dayTimeDuration("-P10D")

return

<components>

<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>

<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>

<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>

<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>

</components>

The preceding query, generates the following XML result:

<components>

<days>-10</days>

<hours>0</hours>

<minutes>0</minutes>

<seconds>0</seconds>

</components>

Related Topics

W3C dayTimeDuration data type description.

 


xf: get-years-from-yearMonthDuration

Extracts the number of years from the years component of $yearMonthDuration-var.

If the value of $yearMonthDuration-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:get-years-from-yearMonthDuration(xf: yearMonthDuration ?$yearMonthDuration-var) —> xs: integer?

Table 12-3 Arguments
Data Type
Argument
Description
xf:yearMonthDuration?
$yearMonthDuration-var
Contains a representation of a time duration which can contain years and months.

Returns

Returns the number of year as an integer from years component of $yearMonthDuration-var.

Examples
Get Years from yearMonthDuration with Years and Months

<years>{xf:get-years-from-yearMonthDuration(xf:yearMonthDuration("P2Y13M"))}</years>

The preceding query generates the following result:

<years>2</years>

Note: Even though 13 months is specified in the month component (13M) of the yearMonthDuration creation string (adding up to an additional year), only 2 years is returned as originally specified by the years component (2Y).
Get Years from yearMonthDuration with Just Negative Years

<years>{xf:get-years-from-yearMonthDuration(xf:yearMonthDuration("-P5Y"))}</years>

The preceding query generates the following result:

<years>-5</years>

Get Years from yearMonthDuration with Just Months

<years>{xf:get-years-from-yearMonthDuration(xf:yearMonthDuration("P10M"))}</years>

The preceding query generates the following result:

<years>0</years>

Related Topics

W3C get-years-from-yearMonthDuration function description.

W3C yearMonthDuration data type description.

 


xf: get-months-from-yearMonthDuration

Extracts the number of months from the months component of $yearMonthDuration-var.

If the value of $yearMonthDuration-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:get-months-from-yearMonthDuration(xf: yearMonthDuration? $yearMonthDuration-var) —> xs: integer?

Table 12-4 Arguments
Data Type
Argument
Description
xf:yearMonthDuration?
$yearMonthDuration-var
Contains a representation of a time duration which can contain years and months.

Returns

Returns the number of months as an integer from months component of $yearMonthDuration-var.

Examples
Get Months from yearMonthDuration with Years and Months

<months>{xf:get-months-from-yearMonthDuration(xf:yearMonthDuration("P2Y10M"))}</months>

The preceding query generates the following result:

<months>10</months>

Get Months from yearMonthDuration with Just Negative Months

<months>{xf:get-months-from-yearMonthDuration(xf:yearMonthDuration("-P5M"))}</months>

The preceding query generates the following result:

<months>-5</months>

Related Topics

W3C get-months-from-yearMonthDuration function description.

W3C yearMonthDurationdata type description.

 


xf: get-days-from-dayTimeDuration

Extracts the number of days from the days component of $dayTimeDuration-var.

If the value of $dayTimeDuration-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:get-days-from-dayTimeDuration(xf: dayTimeDuration?$dayTimeDuration-var) —> xs: integer?

Table 12-5 Arguments
Data Type
Argument
Description
xf:dayTimeDuration ?
$dayTimeDuration-var
Contains a representation of a time duration which can contain days, hours, minutes, and seconds.

Returns

Returns the number of days as an integer from days component of $dayTimeDuration-var.

Examples
Get Days from dayTimeDuration with All Components

<days>{xf:get-days-from-dayTimeDuration(xf:dayTimeDuration("P7DT25H8M20S"))}</days>

The preceding query generates the following result:

<days>7</days>

Note: Even though 25 hours is specified in the hours component (25H) of the dayTimeDuration creation string (adding up to an additional day), only 7 days are returned as originally specified by the days component (7D).
Get Days from dayTimeDuration with Just Negative Days

<days>{xf:get-days-from-dayTimeDuration(xf:dayTimeDuration("-PT4D"))}</days>

The preceding query generates the following result:

<days>-4</days>

Get Days from dayTimeDuration with No Days

<days>{xf:get-days-from-dayTimeDuration(xf:dayTimeDuration("PT2H20S"))}</days>

The preceding query generates the following result:

<days>0</days>

Related Topics

W3C get-days-from-dayTimeDuration function description.

W3C dayTimeDuration data type description.

 


xf: get-hours-from-dayTimeDuration

Extracts the number of hours from the hours component of $dayTimeDuration-var.

If the value of $dayTimeDuration-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:get-hours-from-dayTimeDuration(xf: dayTimeDuration?$dayTimeDuration-var) —> xs: integer?

Table 12-6 Arguments
Data Type
Argument
Description
xf:dayTimeDuration?
$dayTimeDuration-var
Contains a representation of a time duration which can contain days, hours, minutes, and seconds.

Returns

Returns the number as hours as an integer from hours component of $dayTimeDuration-var.

Examples
Get Hours from dayTimeDuration with All Components

<hours>{xf:get-hours-from-dayTimeDuration(xf:dayTimeDuration("P7DT9H65M20S"))}</hours>

The preceding query generates the following result:

<hours>9</hours>

Note: Even though 65 minutes is specified in the minutes component (65M) of the dayTimeDuration creation string (adding up to an additional hour), only 9 hours are returned as originally specified by the hours component (9H).
Get Hours from dayTimeDuration with Just Negative Hours

<hours>{xf:get-hours-from-dayTimeDuration(xf:dayTimeDuration("-PT3H"))}</hours>

The preceding query generates the following result:

<hours>-3</hours>

Get Hours from dayTimeDuration with No Hours

<hours>{xf:get-hours-from-dayTimeDuration(xf:dayTimeDuration("P2DT20S"))}</hours>

The preceding query generates the following result:

<hours>0</hours>

Related Topics

W3C get-hours-from-dayTimeDuration function description.

W3C dayTimeDuration data type description.

 


xf: get-minutes-from-dayTimeDuration

Extracts the number of minutes from the minutes component of $dayTimeDuration-var.

If the value of $dayTimeDuration-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:get-minutes-from-dayTimeDuration(xf: dayTimeDuration?$dayTimeDuration-var) —> xs: integer?

Table 12-7 Arguments
Data Type
Argument
Description
xf:dayTimeDuration
$dayTimeDuration-var
Contains a representation of a time duration which can contain days, hours, minutes, and seconds

Returns

Returns the number as minutes as an integer from minutes component of $dayTimeDuration-var.

Examples
Get Minutes from dayTimeDuration with All Components

<minutes>{xf:get-minutes-from-dayTimeDuration(xf:dayTimeDuration("P7DT9H12M65S"))}</minutes>

The preceding query generates the following result:

<minutes>12</minutes>

Note: Even though 65 seconds is specified in the seconds component (65S) of the dayTimeDuration creation string (adding up to an additional minute), only 12 minutes are returned as originally specified by the minutes component (12M).
Get Minutes from dayTimeDuration with Just Negative Minutes

<minutes>{xf:get-minutes-from-dayTimeDuration(xf:dayTimeDuration("-PT3M"))}</minutes>

The preceding query generates the following result:

<minutes>-3</minutes>

Get Minutes from dayTimeDuration with No Minutes

<minutes>{xf:get-minutes-from-dayTimeDuration(xf:dayTimeDuration("P2DT20S"))}</minutes>

The preceding query generates the following result:

<minutes>0</minutes>

Related Topics

W3C get-minutes-from-dayTimeDuration function description.

W3C dayTimeDuration data type description.

 


xf: get-seconds-from-dayTimeDuration

Extracts the number of seconds from the seconds component of $dayTimeDuration-var.

If the value of $dayTimeDuration-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:get-seconds-from-dayTimeDuration(xf: dayTimeDuration?$dayTimeDuration-var) —> xf: decimal?

Table 12-8 Arguments
Data Type
Argument
Description
xf:dayTimeDuration?
$dayTimeDuration-var
Contains a representation of a time duration which can contain days, hours, minutes, and seconds.

Returns

Returns the number as seconds as an decimal from seconds component of $dayTimeDuration-var.

Examples
Get Seconds from dayTimeDuration with All Components

<seconds>{xf:get-seconds-from-dayTimeDuration(xf:dayTimeDuration("P7DT9H12M14S"))}</seconds>

The preceding query generates the following result:

<seconds>14</seconds>

Get Seconds from dayTimeDuration with Just Negative Seconds

<seconds>{xf:get-seconds-from-dayTimeDuration(xf:dayTimeDuration("-PT7S"))}</seconds>

The preceding query generates the following result:

<seconds>-7</seconds>

Get Seconds from dayTimeDuration with No Seconds

<seconds>{xf:get-seconds-from-dayTimeDuration(xf:dayTimeDuration("P2DT6M"))}</seconds>

The preceding query generates the following result:

<seconds>0</seconds>

Related Topics

W3C get-seconds-from-dayTimeDuration function description.

W3C dayTimeDuration data type description.

 


xf: get-yearMonthDuration-from-dateTimes

Computes the time difference between $dateTime-var1 and $dateTime-var2 and returns it as a yearMonthDuration value.

If the value of $date-var1 follows in time the value of $date-var2, then the returned value is a negative duration. (The date specified in $dateTime-var1 comes before the date specified in $dateTime-var2.) To learn more, see the following Negative Difference example.

The time difference between the values of two dateTime arguments could include years, months, minutes, and seconds but a yearMonthDuration value can only contain years and months, so the time difference is rounded to nearest month. If the time difference between the two dateTime arguments is greater than or equal to 15.5 days (15 days and 12 hours), the month duration is rounded up. To learn more, see the following Round Up and Not Enough to Round Up examples.

If the value of $date-var1 or $date-var2 is the empty sequence, the following error is displayed:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function subtract-dates invocation: expected type [date@http://www.w3.org/2001/XMLSchema], given type empty

Signatures

xf:get-yearMonthDuration-from-dateTimes(xs: dateTime $dateTime-var1, xs: dateTime $dateTime-var2) —>xf: yearMonthDuration

Table 12-9 Arguments
Data Type
Argument
Description
xs:dateTime
$dateTime-var1
Contains a representation of the date and time.
xs:dateTime
$dateTime-var2
Contains a representation of the date and time.

Returns

Returns the time difference between $dateTime-var1 and $dateTime-var2 as a yearMonthDuration value.

Returns a negative yearMonthDuration value if $dateTime-var1 follows in time $dateTime-var2. (The date specified in $dateTime-var1 comes before the date specified in $dateTime-var2.) To learn more, see the following Negative Difference example.

Examples
Positive Difference

The following example query returns a positive years and months duration because the date specified in $datetime-var1 comes after the date specified in $datetime-var2:

let $dateTime-var1 := xs:dateTime("2002-12-26T00:00:01")

return

let $dateTime-var2 := xs:dateTime("2001-11-26T00:00:01")

return

let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>1</years>

<months>1</months>

</result>

Negative Difference

The following example query returns a negative years and month duration because the date specified in $dateTime-var1 comes before the date specified in $dateTime-var2:

let $dateTime-var1 := xs:dateTime("2001-11-26T00:00:01")

return

let $dateTime-var2 := xs:dateTime("2002-12-26T00:00:01")

return

let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>-1</years>

<months>-1</months>

</result>

Round Up

The following example query returns a 1 month yearMonthDuration because there are 15.5 days (15 days and 12 hours) between $dateTime-var1 and $dateTime-var2:

let $dateTime-var1 := xs:dateTime("2002-11-16T12:00:00")

return

let $dateTime-var2 := xs:dateTime("2002-11-01T00:00:00")

return

let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>0</years>

<months>1</months>

</result>

Not Enough to Round Up

The following example query returns a 0 months yearMonthDuration because there are only 15 days, 11 hours, 59 minutes, and 59 seconds (1 second from 15.5 days) between $dateTime-var1 and $dateTime-var2:

let $dateTime-var1 := xs:dateTime("2002-11-16T11:59:59")

return

let $dateTime-var2 := xs:dateTime("2002-11-01T00:00:00")

return

let $mydur := xf:get-yearMonthDuration-from-dateTimes($dateTime-var1, $dateTime-var2)

return

<result>

<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>

<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>

</result>

The preceding query generates the following result:

<result>

<years>0</years>

<months>0</months>

</result>

Related Topics

W3C get-yearMonthDuration-from-dayTimes function description.

W3C yearMonthDuration data type description.

W3C dateTime data type description

 


xf: get-dayTimeDuration-from-dateTimes

Computes the time difference between $dateTime-var1 and $dateTime-var2 and returns it as a dayTimeDuration value.

If the value of $date-var1 follows in time the value of $date-var2, then the returned value is a negative duration.

If the value of $date-var1 or $date-var2 is the empty sequence, the following error is displayed:

Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function subtract-dates invocation: expected type [date@http://www.w3.org/2001/XMLSchema], given type empty

Signatures

xf:get-dayTimeDuration-from-dateTimes(xs: dateTime $dateTime-var1, xs: dateTime $dateTime-var2) —> xf: dayTimeDuration

Table 12-10 Arguments
Data Type
Argument
Description
xs: dateTime
$dateTime-var1
Contains a representation of the date and time.
xs: dateTime
$dateTime-var2
Contains a representation of the date and time.

Returns

Returns the time difference between $dateTime-var1 and $dateTime-var2 as a dayTimeDuration value.

Returns a negative dayTimeDuration value if $dateTime-var1 follows in time $dateTime-var2. (The date specified in $dateTime-var1 comes before the date specified in $dateTime-var2.) To learn more, see the following Negative Difference example.

Examples
Positive Difference

The following example query returns a positive days, hours, minutes, and seconds duration because the date specified in $datetime-var1 comes after the date specified in $datetime-var2:

let $dateTime-var1 := xs:dateTime("2002-12-26T01:01:01")

return

let $dateTime-var2 := xs:dateTime("2001-11-26T00:00:00")

return

let $mydur := xf:get-dayTimeDuration-from-dateTimes($dateTime-var1, $dateTime-var2)

return

<result>

<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>

<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>

<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>

<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>

</result>

The preceding query generates the following result:

<result>

<days>395</days>

<hours>1</hours>

<minutes>1</minutes>

<seconds>1</seconds>

</result>

Negative Difference

The following example query returns a negative days, hours, minutes, and seconds duration because the date specified in $dateTime-var1 comes before the date specified in $dateTime-var2:

let $dateTime-var1 := xs:dateTime("2001-11-26T00:00:00")

return

let $dateTime-var2 := xs:dateTime("2002-12-26T01:01:01")

return

let $mydur := xf:get-dayTimeDuration-from-dateTimes($dateTime-var1, $dateTime-var2)

return

<result>

<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>

<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>

<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>

<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>

</result>

The preceding query generates the following result:

<result>

<days>-395</days>

<hours>-1</hours>

<minutes>-1</minutes>

<seconds>-1</seconds>

</result>

Related Topics

W3C get-dayTimeDuration-from-dateTimes function description.

W3C dayTimeDuration data type description.

W3C dateTime data type description.


  Back to Top       Previous  Next