XQuery Reference

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

XQuery Date and Time Operators Reference

This chapter provides descriptions of the XQuery date and time operators 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 operators. 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 date and time operators available from the mapper functionality:

 


op: subtract-dates

Computes the time difference between $date-var1 and $date-var2. Subtracts the value of $date-var2 from $date-var1.

If the value of $date-var2 follows in time the value of $date-var1, 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

op:subtract-dates(xs: date $date-var1, xs: date $date-var2) —>xf: dayTimeDuration

Table 14-1 Arguments
Data Type
Argument
Description
xs:date
$date-var1
Contains a representation of the date.
xs:date
$date-var2
Contains a representation of the date.

Returns

Returns the time difference between $date-var1 and $date-var2 as dayTimeDuration.

Examples
Positive Difference

The following example query returns a positive number of days because $date-var2 precedes in time $date-var1:

<num_days>{xf:get-days-from-dayTimeDuration(op:subtract-dates(xs:date("2002-08-30"),

xs:date("2001-08-30")))}</num_days>

The preceding query generates the following result:

<num_days>365</num_days>

Negative Difference

The following example query returns a negative number of days because $date-var2 follows in time $date-var1:

<num_days>{xf:get-days-from-dayTimeDuration(op:subtract-dates(xs:date("2001-08-30"),

xs:date("2002-08-30")))}</num_days>

The preceding query generates the following result:

<num_days>-365</num_days>

Related Topics

W3C subtract-dates operator description.

W3C date data type description.

W3C dayTimeDuration operator description.

 


op: subtract-times

Computes the time difference between $time-var1 and $time-var2. Subtracts the value of $time-var2 from $time-var1.

If the value of $time-var2 follows in time the value of $time-var1, 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

op:subtract-times(xs: time $time-var1, xs:time $time-var2) —>xs: dayTimeDuration

Table 14-2 Arguments
Data Type
Argument
Description
xs:time
$time-var1
Contains a representation of time.
xs:time
$time-var2
Contains a representation of time.

Returns

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

Examples
Positive

The following example returns a positive number of minutes because $time-var2 precedes in time $time-var1:

<minutes>{xf:get-minutes-from-dayTimeDuration(op:subtract-times(xf:time("08:01:00"),

xf:time("08:00:00")))}</minutes>

The preceding query generates the following result:

<minutes>1</minutes>

Negative

The following example returns a negative number of days because $time-var2 follows in time $time-var1:

<minutes>{xf:get-minutes-from-dayTimeDuration(op:subtract-times(xf:time("08:00:00"),

xf:time("08:01:00")))}</minutes>

The preceding query generates the following result:

<minutes>-1</minutes>

Related Topics

W3C subtract-times operator description.

W3C date data type description.

W3C dayTimeDuration operator description.

 


op: add-yearMonthDuration-to-dateTime

Adds $yearMonthDuration-var to the date and time specified by $dateTime-var.

Signatures

op:add-yearMonthDuration-to-dateTime(xs: dateTime $dateTime-var, xf: yearMonthDuration $yearMonthDuration-var) —>xs: date Time

Table 14-3 Arguments
Data Type
Argument
Description
xs: date Timee
$dateTime-var
Contains a representation of the date and time.
xf:yearMonthDuration
$yearMonthDuration-var
Contains a time duration that can contain years and months.

Returns

Returns the dateTime result of adding the year and month specified by $yearMonthDuration-var to date and time specified by $dateTime-var. The returned dateTime value has the same timezone as $dateTime-var. If $dateTime-var has no timezone, then the returned dateTime value has the no timezone.

Examples
Simple

The following example query adds a yearMonthDuration value equal to 1 year and 1 month to a dateTime value equal to the date: January 1, 2003 and time: 1:00 AM as shown in the following query:

<dateTime>{

op:add-yearMonthDuration-to-dateTime(xs:dateTime("2003-01-01T01:00:00"), xf:yearMonthDuration("P1Y1M"))

}</dateTime>

The resulting dateTime value equal to the date: February 1, 2004 and the time: 1:00 AM is returned as shown in the following result:

<dateTime>2004-02-01T01:00:00</dateTime>

Related Topics

W3C add-yearMonthDuration-to-dateTime operator description.

W3C yearMonthDuration description.

xf: yearMonthDuration constructor description.

W3C dateTime data type description

xs: dateTime constructor description.

 


op: add-dayTimeDuration-to-dateTime

Adds $dayTimeDuration-var to the date and time specified by $dateTime-var.

Signatures

op:add-dayTimeDuration-to-dateTime(xs: dateTime $dateTime-var, xf: dayTimeDuration $dayTimeDuration-var) —> xs:date Time

Table 14-4 Arguments
Data Type
Argument
Description
xs:date Time
$dateTime-var
Contains a representation of the date and time.
xf:dayTimeDuration
$dayTimeDuration-var
Contains a time duration that can contain days, hours, minutes, and seconds.

Returns

Returns the dateTime result of adding the date and time specified by $dayTimeDuration-var to date and time specified by $dateTime-var. The returned date Time value has the same timezone as $dateTime-var. If $dateTime-var has no timezone, then the returned date Time value has the no timezone.

Examples
Simple

The following example query adds a dayTimeDuration value equal to 1 day, 2 hours, 30 minutes, and 5 seconds to a date Time value equal to the date: January 1, 2003 and time: 1:00 AM as shown in the following query:

<dateTime>{

op:add-dayTimeDuration-to-dateTime(xs:dateTime("2003-01-01T01:00:00"), xf:dayTimeDuration("P1DT2H30M5S"))

}</dateTime>

The resulting date Time value equal to the date: January 2, 2003 and the time: 3:30:05 AM is returned as shown in the following result:

<dateTime>2003-01-02T03:30:05</dateTime>

Related Topics

W3C add-dayTimeDuration-to-dateTime operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.

W3C dateTime data type description

xs: dateTime constructor description.

 


op: subtract-yearMonthDuration-from-dateTime

Subtracts the time duration specified by $yearMonthDuration-var from the date and time specified by $dateTime-var.

Signatures

op:subtract-yearMonthDuration-from-dateTime(xs: dateTime $dateTime-var, xf: yearMonthDuration $yearMonthDuration-var) —>xs:date Time

Table 14-5 Arguments
Data Type
Argument
Description
xs:date Time
$dateTime-var
Contains a representation of the date and time.
xf:yearMonthDuration
$yearMonthDuration-var
Contains a time duration which can contain years and months.

Returns

Returns the date Time value of subtracting the time duration specified by $yearMonthDuration-var from the date and time specified by $dateTime-var.

Examples
Subtracting a Positive yearMonthDuration

The following example query subtracts a positive yearMonthDuration value equal to 1 year and 1 month from a date Time value equal to the date: February 2, 2003 and time: 1:01 AM as shown in the following query:

<positive>{

op:subtract-yearMonthDuration-from-dateTime(xs:dateTime("2003-02-02T01:01:00"), xf:yearMonthDuration("P1Y1M"))

}</positive>

The resulting date Time value equal to the date: January 2, 2002 and time: 1:01 AM is returned as shown in the following result:

<positive>2002-01-02T01:01:00</positive>

Subtracting a Negative yearMonthDuration

The following example query subtracts a negative yearMonthDuration value equal to 1 year and 1 month from a date Time value equal to the date: January 2, 2003 and time: 1:01 AM as shown in the following query:

<negative>{

op:subtract-yearMonthDuration-from-dateTime(xs:dateTime("2003-01-02T01:01:00"), xf:yearMonthDuration("-P1Y1M"))

}</negative>

The resulting date Time value equal to the date: February 2, 2004 and time: 1:01 AM is returned as shown in the following result:

<negative>2004-02-02T01:01:00</negative>

Related Topics

W3C subtract-yearMonthDuration-from-dateTime operator description.

W3C yearMonthDuration description.

xf: yearMonthDuration constructor description.

W3C dateTime data type description

xs: dateTime constructor description.

 


op: subtract-dayTimeDuration-from-dateTime

Subtracts the time duration specified by $dayTimeDuration-var from the date and time specified by $dateTime-var.

Signatures

op:subtract-dayTimeDuration-from-dateTime(xs: dateTime $dateTime-var, xf: dayTimeDuration $ dayTimeDuration-var) —> xs:date Time

Table 14-6 Arguments
Data Type
Argument
Description
xs:date Time
$dateTime-var
Contains a representation of the date and time.
xf:dayTimeDuration
$dayTimeDuration-var
Contains a time duration that can contain days, hours, minutes, and seconds.

Returns

Returns the date Time value of subtracting the time duration specified by $dayTimeDuration-var from the date and time specified by $dateTime-var.

Examples
Subtracting a Positive dayTimeDuration

The following example query subtracts a positive dayTimeDuration value equal to 1 day and 1 minute from a date Time value equal to the date: January 2, 2003 and time: 1:01 AM as shown in the following query:

<positive>{

op:subtract-dayTimeDuration-from-dateTime(xs:dateTime("2003-01-02T01:01:00"), xf:dayTimeDuration("P1DT1M"))

}</positive>

The resulting date Time value equal to the date: January 1, 2003 and time: 1:00 AM is returned as shown in the following result:

<positive>2003-01-01T01:00:00</positive>

Subtracting a Negative dayTimeDuration

The following example query subtracts a negative dayTimeDuration value equal to 1 day and 1 minute from a date Time value equal to the date: January 2, 2003 and time: 1:01 AM as shown in the following query:

<negative>{

op:subtract-dayTimeDuration-from-dateTime(xs:dateTime("2003-01-02T01:01:00"), xf:dayTimeDuration("-P1DT1M"))

}</negative>

The resulting date Time value equal to the date: January 3, 2003 and time: 1:02 AM is returned as shown in the following result:

<negative>2003-01-03T01:02:00</negative>

Related Topics

W3C subtract-dayTimeDuration-from-dateTime operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.

W3C dateTime data type description

xs: dateTime constructor description.

 


op: add-yearMonthDuration-to-date

Adds $yearMonthDuration-var to the date specified by $date-var.

Signatures

op:add-yearMonthDuration-to-date(xs: date $date-var, xf: yearMonthDuration $yearMonthDuration-var) —> xs:date

Table 14-7 Arguments
Data Type
Argument
Description
xs:date
$date-var
Contains a representation of the date.
xf:yearMonthDuration
$yearMonthDuration-var
Contains a time duration that can contain years and months.

Returns

Returns the date result of adding the year and month specified by $yearMonthDuration-var to date specified by $date-var. The returned date value has the same timezone as $date-var. If $date-var has no timezone, then the returned date value has the no timezone.

Examples
Simple

The following example query adds a yearMonthDuration value equal to 1 year and 1 month to a date value equal to the date: January 1, 2003 as shown in the following query:

<date>{

op:add-yearMonthDuration-to-date(xs:date("2003-01-01"), xf:yearMonthDuration("P1Y1M"))

}</date>

The resulting date value equal to the date: February 1, 2004 is returned as shown in the following result:

<date>2004-02-01</date>

Related Topics

W3C add-yearMonthDuration-to-date operator description.

W3C yearMonthDuration description.

xf: yearMonthDuration constructor description.

W3C date data type description

xs: date constructor description.

 


op: add-dayTimeDuration-to-date

Adds $dayTimeDuration-var to the date specified by $date-var.

Signatures

op:add-dayTimeDuration-to-date(xs: date $date-var, xf: dayTimeDuration $dayTimeDuration-var) —>xs:date

Table 14-8 Arguments
Data Type
Argument
Description
xs:date
$date-var
Contains a representation of the date.
xf:dayTimeDuration
$dayTimeDuration-var
Contains a time duration that can contain days, hours, minutes, and seconds.

Returns

Returns the date result of adding the date and time specified by $dayTimeDuration-var to date specified by $date-var. The returned date value has the same timezone as $date-var. If $date-var has no timezone, then the returned date value has the no timezone.

Examples
Simple

The following example query adds a dayTimeDuration value equal to 1 day, 2 hours, 30 minutes, and 5 seconds to a date value equal to the date: January 1, 2003 as shown in the following query:

<date>{

op:add-dayTimeDuration-to-date(xs:date("2003-01-01"), xf:dayTimeDuration("P1DT2H30M5S"))

}</date>

The resulting date value equal to the date: January 2, 2003 is returned as shown in the following result:

<date>2003-01-02</date>

Related Topics

W3C add-dayTimeDuration-to-date operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.

W3C date data type description

xs: date constructor description.

 


op: subtract-yearMonthDuration-from-date

Subtracts the time duration specified by $yearMonthDuration-var from the date specified by $date-var.

Signatures

op:subtract-yearMonthDuration-from-date(xs: date $date-var, xf: yearMonthDuration $yearMonthDuration-var) —> xs:date

Table 14-9 Arguments
Data Type
Argument
Description
xs:date
$date-var
Contains a representation of the date.
xf:yearMonthDuration
$yearMonthDuration-var
Contains a time duration which can contain years and months.

Returns

Returns the date value of subtracting the time duration specified by $yearMonthDuration-var from the date specified by $date-var.

Examples
Subtracting a Positive yearMonthDuration

The following example query subtracts a positive yearMonthDuration value equal to 1 year and 1 month from a date value equal to the date: February 2, 2003 as shown in the following query:

<positive>{

op:subtract-yearMonthDuration-from-date(xs:date("2003-02-02"), xf:yearMonthDuration("P1Y1M"))

}</positive>

The resulting date value equal to the date: January 2, 2002 is returned as shown in the following result:

<positive>2002-01-02</positive>

Subtracting a Negative yearMonthDuration

The following example query subtracts a negative yearMonthDuration value equal to 1 year and 1 month from a date value equal to the date: January 2, 2003 as shown in the following query:

<negative>{

op:subtract-yearMonthDuration-from-date(xs:date("2003-01-02"), xf:yearMonthDuration("-P1Y1M"))

}</negative>

The resulting date value equal to the date: February 2, 2004 is returned as shown in the following result:

<negative>2004-02-02</negative>

Related Topics

W3C subtract-yearMonthDuration-from-date operator description.

W3C yearMonthDuration description.

xf: yearMonthDuration constructor description.

W3C datedata type description

xs: date constructor description.

 


op: subtract-dayTimeDuration-from-date

Subtracts the time duration specified by $dayTimeDuration-var from the date specified by $date-var.

Signatures

op:subtract-dayTimeDuration-from-date(xs: date $date-var, xf: dayTimeDuration $dayTimeDuration-var) —>xs:date

Table 14-10 Arguments
Data Type
Argument
Description
xs:date
$date-var
Contains a representation of the date.
xf:dayTimeDuration
$dayTimeDuration-var
Contains a time duration that can contain days, hours, minutes, and seconds.

Returns

Returns the date value of subtracting the time duration specified by $dayTimeDuration-var from the date specified by $date-var.

Examples
Subtracting a Positive dayTimeDuration

The following example query subtracts a positive dayTimeDuration value equal to 1 day and 1 minute from a date value equal to the date: January 2, 2003 as shown in the following query:

<positive>{

op:subtract-dayTimeDuration-from-date(xs:date("2003-01-02"), xf:dayTimeDuration("P1DT1M"))

}</positive>

The resulting date value equal to the date: January 1, 2003 is returned as shown in the following result:

<positive>2003-01-01</positive>

Subtracting a Negative dayTimeDuration

The following example query subtracts a negative dayTimeDuration value equal to 1 day and 1 minute from a date value equal to the date: January 2, 2003 as shown in the following query:

<negative>{

op:subtract-dayTimeDuration-from-date(xs:date("2003-01-02"), xf:dayTimeDuration("-P1DT1M"))

}</negative>

The resulting date value equal to the date: January 3, 2003 is returned as shown in the following result:

<negative>2003-01-03</negative>

Related Topics

W3C subtract-dayTimeDuration-from-date operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description.

W3C date data type description

xs: date constructor description.

 


op: add-dayTimeDuration-to-time

Adds $dayTimeDuration-var to the time specified by $time-var.

Signatures

op:add-dayTimeDuration-to-time(xs: time $time-var, xf: dayTimeDuration $dayTimeDuration-var) —>xs: time

Table 14-11 Arguments
Data Type
Argument
Description
xs:time
$time-var
Contains a representation of the time.
xf:dayTimeDuration
$dayTimeDuration-var
Contains a time duration that can contain days, hours, minutes, and seconds.

Returns

Returns the time result of adding the date and time specified by $dayTimeDuration-var to time specified by $time-var. The returned time value has the same timezone as $time-var. If $time-var has no timezone, then the returned time value has the no timezone.

Examples
Simple

The following example query adds a dayTimeDuration value equal to 1 day, 2 hours, 30 minutes, and 5 seconds to a time value equal to the time: 1:00 AM as shown in the following query:

<time>{

op:add-dayTimeDuration-to-time(xs:time("01:00:00"), xf:dayTimeDuration("P1DT2H30M5S"))

}</time>

The resulting time value equal to the time: 3:30:05 AM is returned as shown in the following result:

<time>03:30:05</time>

Related Topics

W3C add-dayTimeDuration-to-time operator description.

W3C dayTimeDuration description.

xf: dayTimeDuration constructor description. .

W3C time data type description

xs:time constructor description.

 


op: subtract-dayTimeDuration-from-time

Subtracts the time duration specified by $dayTimeDuration-var from the time specified by $time-var.

Signatures

op:subtract-dayTimeDuration-from-time(xs: time $time-var, xf: dayTimeDuration $dayTimeDuration-var) —>xs: time

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

Returns

Returns the time value of subtracting the time duration specified by $dayTimeDuration-var from the date and time specified by $time-var.

Examples
Subtracting a Positive dayTimeDuration

The following example query subtracts a positive dayTimeDuration value equal to 1 day and 1 minute from a time value equal to the time: 1:01 AM as shown in the following query:

<positive>{

op:subtract-dayTimeDuration-from-time(xs:time("01:01:00"), xf:dayTimeDuration("P1DT1M"))

}</positive>

The resulting time value equal to the time: 1:00 AM is returned as shown in the following result:

<positive>01:00:00</positive>

Subtracting a Negative dayTimeDuration

The following example query subtracts a negative dayTimeDuration value equal to 1 day and 1 minute from a time value equal to the time: 1:01 AM as shown in the following query:

<negative>{

op:subtract-dayTimeDuration-from-time(xs:time("01:01:00"), xf:dayTimeDuration("-P1DT1M"))

}</negative>

The resulting time value equal to the time: 1:02 AM is returned as shown in the following result:

<negative>01:02:00</negative>

Related Topics

W3C subtract-dayTimeDuration-from-time operator description.

W3C dayTimeDuration description.

xf: dayTimeDurationconstructor description.

W3C time data type description

xs:time constructor description.


  Back to Top       Previous  Next