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:
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],
op:
subtract-dates(
xs:
date $date-var1, xs: date $date-var2)
—>xf:
dayTimeDuration
Returns the time difference between $date-var1
and $date-var2
as
dayTimeDuration.
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:
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:
W3C subtract-dates operator description.
W3C date data type description.
W3C dayTimeDuration operator description.
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],
op:
subtract-times
(xs:
time $time-var1
, xs:time
$time-var2
) —>xs:
dayTimeDuration
Returns the time difference between $time-var1
and $time-var2
as dayTimeDuration value.
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:
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:
W3C subtract-times operator description.
W3C date data type description.
W3C dayTimeDuration operator description.
Adds $yearMonthDuration-var
to the date and time specified by $dateTime-var
.
op:
add-yearMonthDuration-to-dateTime(
xs:
dateTime $dateTime-var
, xf:
yearMonthDuration $yearMonthDuration-var) —>xs: date Time
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.
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:
op:add-yearMonthDuration-to-dateTime(xs:dateTime("2003-01-01T01:00:00"), xf:yearMonthDuration("P1Y1M"))
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>
W3C add-yearMonthDuration-to-dateTime operator description.
W3C yearMonthDuration description.
xf: yearMonthDuration constructor description.
W3C dateTime data type description
xs: dateTime constructor description.
Adds $dayTimeDuration-var
to the date and time specified by $dateTime-var
.
op:
add-dayTimeDuration-to-dateTime(
xs:
dateTime $dateTime-var
, xf:
dayTimeDuration $dayTimeDuration-var) —> xs:date Time
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.
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:
op:add-dayTimeDuration-to-dateTime(xs:dateTime("2003-01-01T01:00:00"), xf:dayTimeDuration("P1DT2H30M5S"))
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>
W3C add-dayTimeDuration-to-dateTime operator description.
W3C dayTimeDuration description.
xf: dayTimeDuration constructor description.
W3C dateTime data type description
xs: dateTime constructor description.
Subtracts the time duration specified by $yearMonthDuration-var
from the date and time specified by $dateTime-var
.
op:
subtract-yearMonthDuration-from-dateTime(
xs:
dateTime $dateTime-var
, xf:
yearMonthDuration $yearMonthDuration-var) —>xs:date Time
Returns the date Time
value of subtracting the time duration specified by $yearMonthDuration-var
from the date and time specified by $dateTime-var
.
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:
op:subtract-yearMonthDuration-from-dateTime(xs:dateTime("2003-02-02T01:01:00"), xf:yearMonthDuration("P1Y1M"))
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>
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:
op:subtract-yearMonthDuration-from-dateTime(xs:dateTime("2003-01-02T01:01:00"), xf:yearMonthDuration("-P1Y1M"))
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>
W3C subtract-yearMonthDuration-from-dateTime operator description.
W3C yearMonthDuration description.
xf: yearMonthDuration constructor description.
W3C dateTime data type description
xs: dateTime constructor description.
Subtracts the time duration specified by $dayTimeDuration-var
from the date and time specified by $dateTime-var
.
op:
subtract-dayTimeDuration-from-dateTime(
xs:
dateTime $dateTime-var
, xf:
dayTimeDuration $ dayTimeDuration-var) —> xs:date Time
Returns the date Time
value of subtracting the time duration specified by $dayTimeDuration-var
from the date and time specified by $dateTime-var
.
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:
op:subtract-dayTimeDuration-from-dateTime(xs:dateTime("2003-01-02T01:01:00"), xf:dayTimeDuration("P1DT1M"))
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>
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:
op:subtract-dayTimeDuration-from-dateTime(xs:dateTime("2003-01-02T01:01:00"), xf:dayTimeDuration("-P1DT1M"))
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>
W3C subtract-dayTimeDuration-from-dateTime operator description.
W3C dayTimeDuration description.
xf: dayTimeDuration constructor description.
W3C dateTime data type description
xs: dateTime constructor description.
Adds $yearMonthDuration-var
to the date specified by $date-var
.
op:
add-yearMonthDuration-to-date(
xs:
date $date-var
, xf:
yearMonthDuration $yearMonthDuration-var) —> xs:date
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.
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:
op:add-yearMonthDuration-to-date(xs:date("2003-01-01"), xf:yearMonthDuration("P1Y1M"))
The resulting date value equal to the date: February 1, 2004 is returned as shown in the following result:
W3C add-yearMonthDuration-to-date operator description.
W3C yearMonthDuration description.
xf: yearMonthDuration constructor description.
W3C date data type description
xs: date constructor description.
Adds $dayTimeDuration-var
to the date specified by $date-var
.
op:
add-dayTimeDuration-to-date(
xs:
date $date-var
, xf:
dayTimeDuration $dayTimeDuration-var) —>xs:date
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.
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:
op:add-dayTimeDuration-to-date(xs:date("2003-01-01"), xf:dayTimeDuration("P1DT2H30M5S"))
The resulting date value equal to the date: January 2, 2003 is returned as shown in the following result:
W3C add-dayTimeDuration-to-date operator description.
W3C dayTimeDuration description.
xf: dayTimeDuration constructor description.
W3C date data type description
xs: date constructor description.
Subtracts the time duration specified by $yearMonthDuration-var
from the date specified by $date-var
.
op:
subtract-yearMonthDuration-from-date(
xs:
date $date-var
, xf:
yearMonthDuration $yearMonthDuration-var) —> xs:date
Returns the date value of subtracting the time duration specified by $yearMonthDuration-var
from the date specified by $date-var
.
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:
op:subtract-yearMonthDuration-from-date(xs:date("2003-02-02"), xf:yearMonthDuration("P1Y1M"))
The resulting date value equal to the date: January 2, 2002 is returned as shown in the following result:
<positive>2002-01-02</positive>
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:
op:subtract-yearMonthDuration-from-date(xs:date("2003-01-02"), xf:yearMonthDuration("-P1Y1M"))
The resulting date value equal to the date: February 2, 2004 is returned as shown in the following result:
<negative>2004-02-02</negative>
W3C subtract-yearMonthDuration-from-date operator description.
W3C yearMonthDuration description.
xf: yearMonthDuration constructor description.
W3C datedata type description
xs: date constructor description.
Subtracts the time duration specified by $dayTimeDuration-var
from the date specified by $date-var
.
op:
subtract-dayTimeDuration-from-date(
xs:
date $date-var
, xf:
dayTimeDuration $dayTimeDuration-var) —>xs:date
Returns the date value of subtracting the time duration specified by $dayTimeDuration-var
from the date specified by $date-var
.
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:
op:subtract-dayTimeDuration-from-date(xs:date("2003-01-02"), xf:dayTimeDuration("P1DT1M"))
The resulting date value equal to the date: January 1, 2003 is returned as shown in the following result:
<positive>2003-01-01</positive>
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:
op:subtract-dayTimeDuration-from-date(xs:date("2003-01-02"), xf:dayTimeDuration("-P1DT1M"))
The resulting date value equal to the date: January 3, 2003 is returned as shown in the following result:
<negative>2003-01-03</negative>
W3C subtract-dayTimeDuration-from-date operator description.
W3C dayTimeDuration description.
xf: dayTimeDuration constructor description.
W3C date data type description
xs: date constructor description.
Adds $dayTimeDuration-var
to the time specified by $time-var
.
op:
add-dayTimeDuration-to-time(
xs:
time $time-var
, xf:
dayTimeDuration $dayTimeDuration-var) —>xs: time
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.
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:
op:add-dayTimeDuration-to-time(xs:time("01:00:00"), xf:dayTimeDuration("P1DT2H30M5S"))
The resulting time value equal to the time: 3:30:05 AM is returned as shown in the following result:
W3C add-dayTimeDuration-to-time operator description.
W3C dayTimeDuration description.
xf: dayTimeDuration constructor description. .
W3C time data type description
xs:time constructor description.
Subtracts the time duration specified by $dayTimeDuration-var
from the time specified by $time-var
.
op:
subtract-dayTimeDuration-from-time
(xs:
time $time-var
, xf:
dayTimeDuration $dayTimeDuration-var) —>xs: time
Returns the time value of subtracting the time duration specified by $dayTimeDuration-var
from the date and time specified by $time-var
.
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:
op:subtract-dayTimeDuration-from-time(xs:time("01:01:00"), xf:dayTimeDuration("P1DT1M"))
The resulting time value equal to the time: 1:00 AM is returned as shown in the following result:
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:
op:subtract-dayTimeDuration-from-time(xs:time("01:01:00"), xf:dayTimeDuration("-P1DT1M"))
The resulting time value equal to the time: 1:02 AM is returned as shown in the following result:
W3C subtract-dayTimeDuration-from-time operator description.
W3C dayTimeDuration description.
xf: dayTimeDurationconstructor description.
W3C time data type description
xs:time constructor description.