XQuery Reference

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

XQuery Date Functions Reference

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

 


xf: get-year-from-dateTime

Extracts the year from $dateTime-var.

If the value of $dateTime-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-year-from-dateTime(xs: dateTime?$dateTime-var) —> xs: integer?

Table 9-1 Arguments
Data Type
Argument
Description
xs:date Time
$dateTime-var
Contains a representation of the date and time.

Returns

Returns the year as an integer from $dateTime-var.

Examples
Simple

When you invoke the following query:

<year>{xf:get-year-from-dateTime("2002-08-30T22:21:01")}</year>

The preceding query generates the following result:

<year>2002</year>

Related Topics

W3C get-year-from-dateTime function description.

W3C dateTime data type description.

 


xf: get-month-from-dateTime

Extracts the month from $dateTime-var.

If the value of $dateTime-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-month-from-dateTime(xs: dateTime? $dateTime-var) —>xs: integer?

Table 9-2 Arguments
Data Type
Argument
Description
xs: dateTime?
$dateTime-var
Contains a representation of the date and time.

Returns

Returns the month as an integer from $dateTime-var.

Examples
Simple

When you invoke the following query:

<month>{xf:get-month-from-dateTime("2002-08-30T22:21:01")}</month>

The preceding query generates the following result:

<month>8</month>

Related Topics

W3C get-month-from-dateTime function description.

W3C dateTime data type description.

 


xf: get-day-from-dateTime

Extracts the day from $dateTime-var.

If the value of $dateTime-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-day-from-dateTime(xs: dateTime $dateTime-var) —> xs:integer?

Table 9-3 Arguments
Data Type
Argument
Description
xs: dateTime?
$dateTime-var
Contains a representation of the date and time.

Returns

Returns the day as an integer from $dateTime-var.

Examples
Simple

When you invoke the following query:

<day>{xf:get-day-from-dateTime("2002-08-30T22:21:01")}</day>

The preceding query generates the following result:

<day>30</day>

Related Topics

W3C get-day-from-dateTime function description.

W3C dateTime data type description.

 


xf: get-hours-from-dateTime

Extracts the hours from $dateTime-var.

If the value of $dateTime-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-dateTime(xs: dateTime?$dateTime-var) —> xs: integer?

Table 9-4 Arguments
Data Type
Argument
Description
xs:date Time?
$dateTime-var
Contains a representation of the date and time.

Returns

Returns the hours as an integer from $dateTime-var.

Examples
Simple

When you invoke the following query:

<hours>{xf:get-hours-from-dateTime("2002-08-30T22:21:01")}</hours>

The preceding query generates the following result:

<hours>22</hours>

Timezone

The following example uses the get-hours-from-dateTime function with a timezone:

<hours>{xf:get-hours-from-dateTime("2002-08-30T14:21:01-05:00")}</hours>

The preceding query generates the following result:

<hours>19</hours>

In the preceding query, the -05:00 string specifies the time is specified in the Eastern Standard timezone which is 5 hours behind Coordinated Universal Time (UTC). The hours are reported in Coordinated Universal Time (UTC), so 5 hours are added to 14 hours of the Eastern Standard timezone, resulting in 19 hours in Coordinated Universal Time (UTC).

Related Topics

W3C get-hours-from-dateTime function description.

W3C dateTime data type description.

 


xf: get-minutes-from-dateTime

Extracts the minutes from $dateTime-var.

If the value of $dateTime-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-dateTime(xs: dateTime?$dateTime-var) —> xs: integer?

Table 9-5 Arguments
Data Type
Argument
Description
xs:date Time?
$dateTime-var
Contains a representation of the date and time.

Returns

Returns the minutes as an integer from $dateTime-var.

Examples
Simple

When you invoke the following query:

<minutes>{xf:get-minutes-from-dateTime("2002-08-30T22:21:01")}</minutes>

The preceding query generates the following result:

<minutes>21</minutes>

Related Topics

W3C get-minutes-from-dateTime function description.

W3C dateTime data type description.

 


xf: get-seconds-from-dateTime

Extracts the seconds from $dateTime-var.

If the value of $dateTime-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-dateTime(xs: dateTime? $dateTime-var) —> xs:xs: decimal?

Table 9-6 Arguments
Data Type
Argument
Description
xs:date Time?
$dateTime-var
Contains a representation of the date and time

Returns

Returns the seconds as an decimal from $dateTime-var.

Examples
Simple

When you invoke the following query:

<seconds>{xf:get-seconds-from-dateTime("2002-08-30T22:21:01")}</seconds>

The preceding query generates the following result:

<seconds>1</seconds>

Related Topics

W3C get-seconds-from-dateTime function description.

W3C dateTime data type description.

 


xf: get-timezone-from-dateTime

Extracts the current timezone from $dateTime-var and returns it as a string.

If $dateTime-var does not contain a timezone, the empty sequence is returned.

If the value of $dateTime-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-timezone-from-dateTime(xs: dateTime? $dateTime-var) —> xs: string ?

Table 9-7 Arguments
Data Type
Argument
Description
xs:date Time?
$dateTime-var
Contains a representation of the date and time.

Returns

Returns the current timezone as a string from $dateTime-var.

Returns an empty sequence, if $dateTime-var does not contain a timezone. (See examples below.)

Examples
Timezone

The following example uses the get-timezone-from-dateTime function with a timezone:

<tz>{xf:get-timezone-from-dateTime("2002-08-30T14:21:01-05:00")}</tz>

The preceding query generates the following result:

<tz>-05:00</tz>

In the preceding query, the -05:00 string specifies the time is specified in the Eastern Standard time zone which is 5 hours behind Universal Time, Coordinated (UTC).

UTC Timezone

The following example uses the get-timezone-from-dateTime function with a timezone:

<tz>{xf:get-timezone-from-dateTime("2002-08-30T14:21:01Z")}</tz>

The preceding query generates the following result:

<tz>00:00</tz>

In this example, the Z means the time is being specified in Universal Coordinated, Time (UTC), so no timezone is reported.

No Timezone

The following is an example of using the get-timezone-from-dateTime function with no timezone specified:

<tz>{xf:get-timezone-from-dateTime("2002-08-30T22:21:01")}</tz>

The preceding query generates the following result:

<tz/>

Related Topics

W3C get-timezone-from-dateTime function description.

W3C dateTime data type description.

 


xf: get-year-from-date

Extracts the year from $date-var.

If the value of $date-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-year-from-date(xs: date? $date-var) —> xs: integer?

Table 9-8 Arguments
Data Type
Argument
Description
xs:date?
$date-var
Contains a representation of the date.

Returns

Returns the year as an integer from $date-var.

Examples
Simple

When you invoke the following query:

<year>{xf:get-year-from-date("2002-08-30")}</year>

The preceding query generates the following result:

<year>2002</year>

Related Topics

W3C get-year-from-date function description.

W3C date data type description.

 


xf: get-month-from-date

Extracts the month from $date-var.

If the value of $date-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-month-from-date(xs: date? $date-var) —> xs: integer?

Table 9-9 Arguments
Data Type
Argument
Description
xs:date?
$date-var
Contains a representation of the date.

Returns

Returns the month as an integer from $date-var.

Examples
Simple

When you invoke the following query:

<month>{get-month-from-date("2002-08-30")}</month>

The preceding query generates the following result:

<month>8</month>

Related Topics

W3C get-month-from-date function description.

W3C date data type description.

 


xf: get-day-from-date

Extracts the day from $date-var.

If the value of $date-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-day-from-date(xs: date? $date-var) —>xs: integer?

Table 9-10 Arguments
Data Type
Argument
Description
xs:date?
$date-var
Contains a representation of the date.

Returns

Returns the day as an integer from $date-var.

Examples
Simple

When you invoke the following query:

<day>{xf:get-day-from-date("2002-08-30")}</day>

The preceding query generates the following result:

<day>30</day>

Related Topics

W3C get-day-from-date function description.

W3C date data type description.

 


xf: get-timezone-from-date

Extracts the current timezone from $date-var.

If $date-var does not contain a timezone, the empty sequence is returned.

If the value of $date-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-timezone-from-date(xs: date?$date-var) —>xs: string ?

Table 9-11 Arguments
Data Type
Argument
Description
xs: date?
$date-var
Contains a representation of the date.

Returns

Returns the current timezone as a string from $date-var.

Returns an empty sequence, if $date-var does not contain a timezone. (See examples below.)

Examples
Timezone

The following example uses the get-timezone-from-date function with a timezone:

<tz>{xf:get-timezone-from-date(xs:date("2002-08-30-05:00"))}</tz>

The preceding query generates the following result:

<tz>-05:00</tz>

In the preceding query, the -05:00 string specifies the time is specified in the Eastern Standard timezone which is 5 hours behind Coordinated Universal Time (UTC).

UTC Timezone

The following example uses the get-timezone-from-date function with a timezone:

<tz>{xf:get-timezone-from-date(xs:date("2002-08-30Z"))}</tz>

The preceding query generates the following result:

<tz>00:00</tz>

In this preceding query, the Z means the time is being specified in Coordinated Universal Time (UTC), so no timezone is reported.

No Timezone

The following is an example of using the get-timezone-from-date function with no timezone specified:

<tz>{xf:get-timezone-from-date(xs:date("2002-08-30"))}</tz>

The preceding query generates the following result:

<tz/>

Related Topics

W3C get-timezone-from-date function description.

W3C date data type description.

 


xf: get-hours-from-time

Extracts the hours from $time-var.

If the value of $time-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-time(xs: time? $time-var) —>xs: integer?

Table 9-12 Arguments
Data Type
Argument
Description
xs: time?
$time-var
Contains a representation of time.

Returns

Returns the hours as an integer from $time-var.

Examples
Simple

The following is a simple example using the get-hours-from-time function:

<hours>{xf:get-hours-from-time("22:21:01")}</hours>

The preceding query generates the following result:

<hours>22</hours>

Timezone

The following example uses the get-hours-from-time function with a timezone:

<hours>{xf:get-hours-from-time("14:21:01-05:00")}</hours>

The preceding query generates the following result:

<hours>19</hours>

In the preceding query, the -05:00 string specifies the time is specified in the Eastern Standard timezone which is 5 hours behind Coordinated Universal Time (UTC). The hours are reported in Coordinated Universal Time (UTC), so 5 hours are added to 14 hours of the Eastern Standard timezone, resulting in 19 hours in Coordinated Universal Time (UTC).

Related Topics

W3C get-hours-from-time function description.

W3C time data type description.

 


xf: get-minutes-from-time

Extracts the minutes from $time-var.

If the value of $time-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-time(xs: time? $time-var) —> xs: integer?

Table 9-13 Arguments
Data Type
Argument
Description
xs: time?
$time-var
Contains a representation of time.

Returns

Returns the minutes as an integer from $time-var.

Examples
Simple

The following is a simple example using the get-minutes-from-time function:

<minutes>{xf:get-minutes-from-time("22:21:01")}</minutes>

The preceding query generates the following result:

<minutes>21</minutes>

Timezone

The following example uses the get-minutes-from-time function with a timezone:

<minutes>{xf:get-minutes-from-time("14:21:01-05:00")}</minutes>

The preceding query generates the following result:

<minutes>21</minutes>

Related Topics

W3C get-minutes-from-time function description.

W3C time data type description.

 


xf: get-seconds-from-time

Extracts the seconds from $time-var.

If the value of $time-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-time(xs: time?$time-var) —> xs: decimal ?

Table 9-14 Arguments
Data Type
Argument
Description
xs:time?
$time-var
Contains a representation of time.

Returns

Returns the seconds as an decimal from $time-var.

Examples
Simple

The following is a simple example using the get-seconds-from-time function:

<seconds>{xf:get-seconds-from-time("22:21:01")}</seconds>

The preceding query generates the following result:

<seconds>1</seconds>

Timezone

The following example uses the get-seconds-from-time function with a timezone:

<seconds>{xf:get-seconds-from-time("14:21:01-05:00")}</seconds>

The preceding query generates the following result:

<seconds>1</seconds>

Related Topics

W3C get-seconds-from-time function description.

W3C time data type description.

 


xf: get-timezone-from-time

Extracts the current timezone from $time-var.

If $time-var does not contain a timezone, the empty sequence is returned.

If the value of $time-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-timezone-from-time(xs: time? $time-var) —>xs: string ?

Table 9-15 Arguments
Data Type
Argument
Description
xs:time?
$time-var
Contains a representation of the date and time.

Returns

Returns the current timezone as a string from $time-var.

Returns an empty sequence, if $time-var does not contain a timezone. (See examples below.)

Examples
Timezone

The following example uses the get-timezone-from-time function with a timezone:

<tz>{xf:get-timezone-from-time(xs:time("14:21:01-05:00"))}</tz>

The preceding query generates the following result:

<tz>-05:00</tz>

In the preceding query, the -05:00 string specifies the time is specified in the Eastern Standard timezone which is 5 hours behind Coordinated Universal Time (UTC).

UTC Timezone

The following example uses the get-timezone-from-time function with a timezone:

<tz>{get-timezone-from-time(xs:time("14:21:01Z"))}</tz>

The preceding query generates the following result:

<tz>00:00</tz>

In this preceding query, the Z means the time is being specified in Coordinated Universal Time (UTC), so no timezone is reported.

No Timezone

The following is an example of using the get-timezone-from-time function with no timezone specified:

<tz>{xf:get-timezone-from-time(xs:time("22:21:01"))}</tz>

Returns an empty sequence, because $time-var does not contain a timezone.

Related Topics

W3C get-timezone-from-time function description.

W3C time data type description.

 


xf: add-timezone-to-dateTime

Adds a time zone to a dateTime value. The timezone added to the date Time value is either the implicit time zone or passed in with the optional argument: $dayTimeDuration-var.

Note: The implicit time zone is obtained from the current environment. For example, if the time zone specified on your machine is the PSD (Pacific Daylight Savings), the implicit time zone would be -07:00.

Adds a time zone to a date Timevalue by invoking the following steps:

  1. If the specified date Time value already has a time zone value, that time zone is removed from the date Time value. Since the purpose of the add-timezone-to-dateTime function is to add a timezone to a dateTime value without a timezone, in most cases the passed in date Time value (argument: $dateTime-var) will have not have a time zone, so this step will be ignored as shown in the preceding examples.
  2. Adds the time zone, specified by either the optional argument $dayTimeDuration-var or the implicit time, to the date Time value (argument: $dateTime-var).
  3. Converts the new date Time value generated by the previous step to a Universal Coordinated Time (UTC) time zone value.
Signatures

xf:add-timezone-to-dateTime(xs: dateTime $dateTime-var) —>xs: date Time

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

Table 9-16 Arguments
Data Type
Argument
Description
xs: date Time
$dateTime-var
Contains a representation of the date and time.
xf:day TimeDuration
$dayTimeDuration-var
Time zone to add to $dateTime-var. (Optional, if not specified the implicit time zone is used)

Returns

Returns a date Time with a time zone.

If $dateTime-var contains a time zone and the optional argument $dayTimeDuration-var is not specified, the passed in date and time are returned with no conversion.

Examples
Adding the Specified Timezone to the dateTime Value

The following example adds the specified time zone to the specified date Time value. In this example, the specified date Time value: 2002-12-06T12:00:00, initially does not have a timezone zone associated with it.

Adding the specified time zone to the specified date Time value, by invoking xf:add-timezone-to-dateTime(xs:dateTime("2002-12-06T12:00:00", dayTimeDuration("-PT7H"))), causes the following internal conversion steps:

  1. In this example, the time zone is specified with the day Time Duration string: -PT7H, which is the Pacific Daylight Savings Time (PST) time zone (-07:00). This specified time zone: -07:00 is added to the specified date Time value: 2002-12-06T12:00:00 resulting in the following internal date Time value: 2002-12-06T12:00:00-07:00.
  2. This new date Time value: 2002-12-06T19:00:00-07:00 is converted to Universal Coordinated Time (UTC), resulting in the following date Time value: 2002-12-06T19:00:00Z, as shown in the following example query:

let $dateTimeWithNoTimezone := xs:dateTime("2002-12-06T12:00:00")

return

<result>

<dateTimeWithNoTimezone>{$dateTimeWithNoTimezone}</dateTimeWithNoTimezone>

<dateTimeWithTimeZoneAdded>{ xf:add-timezone-to-dateTime(xs:dateTime($dateTimeWithNoTimezone),

xf:dayTimeDuration("-PT7H")) }</dateTimeWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<dateTimeWithNoTimezone>2002-12-06T12:00:00</dateTimeWithNoTimezone>

<dateTimeWithTimeZoneAdded>2002-12-06T19:00:00Z</dateTimeWithTimeZoneAdded>

</result>

Note: The Z at the end of the 2002-12-06T19:00:00Z value specifies that the dateTime value is in UTC time.
Adding the Implicit Timezone to the dateTime Value

The following example adds the implicit time zone to the specified date Time value. In this example, the specified date Time value: 2002-12-06T12:00:00, initially does not have a timezone zone associated with it.

In this example, the implicit time zone is assumed to be -07:00, the Pacific Daylight Savings Time (PST) time zone. (The implicit time zone is the default time zone for the current machine.)

Adding the implicit time zone to the specified date Time value, by invoking xf:add-timezone-to-dateTime(xs:dateTime("2002-12-06T12:00:00")), causes the following internal conversion steps:

  1. The implicit time zone: -07:00 is added to the specified date Time value: 2002-12-06T12:00:00 resulting in the following internal dateTime value: 2002-12-06T12:00:00-07:00.
  2. This new date Time value: 2002-12-06T19:00:00-07:00 is converted to Universal Coordinated Time (UTC), resulting in the following dateTime value: 2002-12-06T19:00:00Z, as shown in the following example query:

let $dateTimeWithNoTimezone := xs:dateTime("2002-12-06T12:00:00")

return

<result>

<dateTimeWithNoTimezone>{$dateTimeWithNoTimezone}</dateTimeWithNoTimezone>

<dateTimeWithTimeZoneAdded>{ xf:add-timezone-to-dateTime(xs:dateTime($dateTimeWithNoTimezone)) }

</dateTimeWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<dateTimeWithNoTimezone>2002-12-06T12:00:00</dateTimeWithNoTimezone>

<dateTimeWithTimeZoneAdded>2002-12-06T19:00:00Z</dateTimeWithTimeZoneAdded>

</result>

Note: The Z at the end of the 2002-12-06T19:00:00Z value specifies that the dateTime value is in UTC time.
Note: The results of this query maybe be different for your machine because the implicit time zone may be different.
Related Topics

W3C add-timezone-to-dateTime function description.

W3C dateTime data type description.

W3C dayTimeDuration operator description.

 


xf: remove-timezone-from-dateTime

Removes a time zone from a dateTime value. The dateTime value with a time zone is localized to either the implicit time zone or to time zone specified by the argument: $dayTimeDuration-var and then the timezone indicator is removed.

If the specified dateTime value has no time zone associated with it, then the implicit time zone is added to dateTime value before the localization described above is done. Since the purpose of the remove-timezone-to-dateTime function is to remove a timezone from a dateTime value with a timezone, in most cases the passed in dateTime value (argument: $dateTime-var) will have a time zone, so this step will be ignored as shown in the preceding examples.

Note: The implicit time zone is obtained from the current environment. For example, if the time zone specified on your machine is the PSD (Pacific Daylight Savings), the implicit time zone would be -07:00.
Signatures

xf:remove-timezone-from-dateTime(xs: dateTime $dateTime-var) —> xs: dateTime

xf:remove-timezone-from-dateTime(xs: dateTime $dateTime-var, xf: dayTimeDuration, $dayTimeDuration-var) —> xs: dateTime

Table 9-17 Arguments
Data Type
Argument
Description
xs:date Time
$dateTime-var
Contains a representation of the date and time.
xf: day Time Duration
$dayTimeDuration-var
Time zone to remove from $dateTime-var. (Optional, if not specified the implicit time zone is used)

Returns

Returns a dateTime without a time zone.

If $dateTime-var does not contain a time zone and optional argument $dayTimeDuration-var is not specified, the passed in date and time are returned with no conversion.

Examples
Removing the Specified Timezone From a dateTime Value

The following example removes the specified time zone from the specified dateTime value.

In this example, the passed in dateTime value: 2002-12-06T12:00:00Z is specified with the UTC time zone specified by the time zone indicator: Z.

The time zone is specified with the dayTimeDuration string: -PT7H, in the preceding query which is the Pacific Daylight Savings Time (PST) time zone (-07:00).

The passed in dateTime value: 2002-12-06T12:00:00Z specified with the UTC time zone is localized to PST time zone and the time zone indicator (Z) is removed, as shown in the following example query:

let $dateTimeWithUTCTimezone := xs:dateTime("2002-12-06T12:00:00Z")

return

<result>

<dateTimeWithUTCTimezone>{$dateTimeWithUTCTimezone}</dateTimeWithUTCTimezone>

<dateTimeWithTimeZoneAdded>{ xf:remove-timezone-from-dateTime(xs:dateTime($dateTimeWithUTCTimezone,

xf:dayTimeDuration("-PT7H"))) }</dateTimeWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<dateTimeWithUTCTimezone>2002-12-06T12:00:00Z</dateTimeWithUTCTimezone>

<dateTimeWithTimeZoneAdded>2002-12-06T05:00:00</dateTimeWithTimeZoneAdded>

</result>

Removing the Implicit Timezone From the dateTime Value

The following example removes the implicit time zone from the specified dateTime value. In this example, the passed in dateTime value: 2002-12-06T12:00:00Z is specified with the UTC time zone specified by the time zone indicator: Z.

In this example, the implicit time zone is assumed to be -07:00, the Pacific Daylight Savings Time (PST) time zone. (The implicit time zone is the default time zone for the current machine.)

The passed in dateTime value: 2002-12-06T12:00:00Z specified with the UTC time zone is localized to PST time zone and the time zone indicator (Z) is removed, as shown in the following example query:

let $dateTimeWithUTCTimezone := xs:dateTime("2002-12-06T12:00:00Z")

return

<result>

<dateTimeWithUTCTimezone>{$dateTimeWithUTCTimezone}</dateTimeWithUTCTimezone>

<dateTimeWithTimeZoneAdded>{ xf:remove-timezone-from-dateTime(xs:dateTime($dateTimeWithUTCTimezone)) }

</dateTimeWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<dateTimeWithUTCTimezone>2002-12-06T12:00:00Z</dateTimeWithUTCTimezone>

<dateTimeWithTimeZoneAdded>2002-12-06T05:00:00</dateTimeWithTimeZoneAdded>

</result>

Related Topics

W3C remove-timezone-from-dateTime function description.

W3C dateTime data type description.

W3C dayTimeDuration operator description.

 


xf: add-timezone-to-date

Adds a time zone to a date value. The timezone added to the date value is either the implicit time zone or passed in with the optional argument: $dayTimeDuration-var.

Note: The implicit time zone is obtained from the current environment. For example, if the time zone specified on your machine is the PSD (Pacific Daylight Savings), the implicit time zone would be -07:00.

Adds a time zone to a date value by invoking the following steps:

If the specified date value already has a time zone value, that time zone is removed from the date value. Since the purpose of the add-timezone-to-date function is to add a timezone to a date value without a timezone, in most cases the passed in date value (argument: $date-var) will have not have a time zone, so this step will be ignored as shown in the preceding examples.

Adds the time zone, specified by either the optional argument $dayTimeDuration-var or the implicit time, to the date value (argument: $date-var).

Converts the new date value generated by the previous step to a Universal Coordinated Time (UTC) time zone value.

Signatures

xf:add-timezone-to-date(xs: date $date-var) —>xs: date

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

Table 9-18 Arguments
Data Type
Argument
Description
xs: date?
$date-var
Contains a representation of the date.
xf:dayTimeDuration
$dayTimeDuration-var
Time zone to add to $date-var. (Optional, if not specified the implicit time zone is used).

Returns

Returns a date with a time zone.

If $date-var contains a time zone and optional argument $dayTimeDuration-var is not specified, the passed in date and time are returned with no conversion.

Examples
Adding the Specified Timezone to the date Value

The following example adds the specified time zone to the specified date value. In this example, the specified date value: 2002-12-06, initially does not have a timezone zone associated with it.

Adding the specified time zone to the specified date value, by invoking xf:add-timezone-to-date(xs:date("2002-12-06", dayTimeDuration("-PT7H"))), causes the following internal conversion steps:

  1. In this example, the time zone is specified with the day Time Duration string: -PT7H, which is the Pacific Daylight Savings Time (PST) time zone (-07:00). This specified time zone: -07:00 is added to the specified date value: 2002-12-06 resulting in the following internal date value: 2002-12-06-07:00.
  2. This new date value: 2002-12-06-07:00 is converted to Universal Coordinated Time (UTC), resulting in the following date value: 2002-12-06Z, as shown in the following example query:

let $dateWithNoTimezone := xs:date("2002-12-06")

return

<result>

<dateWithNoTimezone>{$dateWithNoTimezone}</dateWithNoTimezone>

<dateWithTimeZoneAdded>{ xf:add-timezone-to-date(xs:date($dateWithNoTimezone),

xf:dayTimeDuration("-PT7H")) }</dateWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<dateWithNoTimezone>2002-12-06</dateWithNoTimezone>

<dateWithTimeZoneAdded>2002-12-06Z</dateWithTimeZoneAdded>

</result>

Note: The Z at the end of the 2002-12-06Z value specifies that the date value is in UTC time.
Adding the Implicit Timezone to the date Value

The following example adds the implicit time zone to the specified date value. In this example, the specified date value: 2002-12-06, initially does not have a timezone zone associated with it.

In this example, the implicit time zone is assumed to be -07:00, the Pacific Daylight Savings Time (PST) time zone. (The implicit time zone is the default time zone for the current machine.)

Adding the implicit time zone to the specified date value, by invoking xf:add-timezone-to-date(xs:date("2002-12-06")), causes the following internal conversion steps:

  1. The implicit time zone: -07:00 is added to the specified date value: 2002-12-06 resulting in the following internal date value: 2002-12-06-07:00.
  2. This new date value: 2002-12-06-07:00 is converted to Universal Coordinated Time (UTC), resulting in the following date value: 2002-12-06Z, as shown in the following example query:

let $dateWithNoTimezone := xs:date("2002-12-06")

return

<result>

<dateWithNoTimezone>{$dateWithNoTimezone}</dateWithNoTimezone>

<dateWithTimeZoneAdded>{ xf:add-timezone-to-date(xs:date($dateWithNoTimezone)) }

</dateWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<dateWithNoTimezone>2002-12-06</dateWithNoTimezone>

<dateWithTimeZoneAdded>2002-12-06Z</dateWithTimeZoneAdded>

</result>

Note: The Z at the end of the 2002-12-06Z value specifies that the date value is in UTC time.
Note: The results of this query maybe be different for your machine because the implicit time zone may be different.
Related Topics

W3C add-timezone-to-date function description.

W3C date data type description.

W3C dayTimeDuration operator description.

 


xf: add-timezone-to-time

Adds a time zone to a time value. The timezone added to the time value is either the implicit time zone or passed in with the optional argument: $dayTimeDuration-var.

Note: The implicit time zone is obtained from the current environment. For example, if the time zone specified on your machine is the PSD (Pacific Daylight Savings), the implicit time zone would be -07:00.

Adds a time zone to a time value by invoking the following steps:

  1. If the specified time value already has a time zone value, that time zone is removed from the time value. Since the purpose of the add-timezone-to-time function is to add a timezone to a time value without a timezone, in most cases the passed in time value (argument: $time-var) will have not have a time zone, so this step will be ignored as shown in the preceding examples.
  2. Adds the time zone, specified by either the optional argument $dayTimeDuration-var or the implicit time, to the timevalue (argument: $time-var).
  3. Converts the new time value generated by the previous step to a Universal Coordinated Time (UTC) time zone value.
Signatures

xf:add-timezone-to-time(xs: time $time-var) —>xs: time

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

Table 9-19 Argument
Arguments
Data Type
Description
xs:time
$time-var
Contains a representation of the time.
xf:day Time Duration
$dayTimeDuration-var
Time zone to remove to $time-var. (Optional, if not specified the implicit time zone is used).

Returns

Returns a time with a time zone.

If $time-var contains a time zone and optional argument $dayTimeDuration-var is not specified, the passed in date and time are returned with no conversion.

Examples
Adding the Specified Timezone to the time Value

The following example adds the specified time zone to the specified time value. In this example, the specified time value: 12:00:00, initially does not have a timezone zone associated with it.

Adding the specified time zone to the specified time value, by invoking xf:date-timezone-to-time(xs:time("12:00:00", dayTimeDuration("-PT7H"))), causes the following internal conversion steps:

In this example, the time zone is specified with the day Time Duration string: -PT7H, which is the Pacific Daylight Savings Time (PST) time zone (-07:00). This specified time zone: -07:00 is added to the specified time value: 12:00:00 resulting in the following internal time value: 12:00:00-07:00.

This new time value: 19:00:00-07:00 is converted to Universal Coordinated Time (UTC), resulting in the following time value: 19:00:00Z, as shown in the following example query:

let $timeWithNoTimezone := xs:time("12:00:00")

return

<result>

<timeWithNoTimezone>{$timeWithNoTimezone}</timeWithNoTimezone>

<timeWithTimeZoneAdded>{ xf:add-timezone-to-time(xs:time($timeWithNoTimezone),

xf:dayTimeDuration("-PT7H")) }</timeWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<timeWithNoTimezone>12:00:00</timeWithNoTimezone>

<timeWithTimeZoneAdded>19:00:00Z</timeWithTimeZoneAdded>

</result>

Note: The Z at the end of the 19:00:00Z value specifies that the time value is in UTC time.
Adding the Implicit Timezone to the time Value

The following example adds the implicit time zone to the specified time value. In this example, the specified time value: 12:00:00, initially does not have a timezone zone associated with it.

In this example, the implicit time zone is assumed to be -07:00, the Pacific Daylight Savings Time (PST) time zone. (The implicit time zone is the default time zone for the current machine.)

Adding the implicit time zone to the specified time value, by invoking xf:add-timezone-to-time(xs:time("12:00:00")), causes the following internal conversion steps:

The implicit time zone: -07:00 is added to the specified time value: 12:00:00 resulting in the following internal time value: 12:00:00-07:00.

This new time value: 19:00:00-07:00 is converted to Universal Coordinated Time (UTC), resulting in the following time value: 19:00:00Z, as shown in the following example query:

let $timeWithNoTimezone := xs:time("12:00:00")

return

<result>

<timeWithNoTimezone>{$timeWithNoTimezone}</timeWithNoTimezone>

<timeWithTimeZoneAdded>{ xf:add-timezone-to-time(xs:time($timeWithNoTimezone)) }

</timeWithTimeZoneAdded>

</result>

The preceding query produces the following result:

<result>

<timeWithNoTimezone>12:00:00</timeWithNoTimezone>

<timeWithTimeZoneAdded>19:00:00Z</timeWithTimeZoneAdded>

</result>

Note: The Z at the end of the 19:00:00Z value specifies that the time value is in UTC time.
Note: The results of this query maybe be different for your machine because the implicit time zone may be different.
Related Topics

W3C add-timezone-to-time function description.

W3C time data type description.

W3C dayTimeDuration operator description.

 


xf: remove-timezone-from-time

Removes a time zone from a time value. The time value with a time zone is localized to either the implicit time zone or to time zone specified by the argument: $dayTimeDuration-var and then the timezone indicator is removed.

If the specified time value has no time zone associated with it, then the implicit time zone is added to time value before the localization described above is done. Since the purpose of the remove-timezone-to-time function is to remove a timezone from a time value with a timezone, in most cases the passed in time value (argument: $time-var) will have a time zone, so this step will be ignored as shown in the following examples.

Note: The implicit time zone is obtained from the current environment. For example, if the time zone specified on your machine is the PSD (Pacific Daylight Savings), the implicit time zone would be -07:00.
Signatures

xf:remove-timezone-from-time(xs: time$time-var) —>xs: time

xf:remove-timezone-from-time(xs: time $time-var, xf: dayTimeDuration, $dayTimeDuration-var) —> xs: time

Table 9-20 Arguments
Data Type
Argument
Description
xs:time
$time-var
Contains a representation of the time.
xf:dayTimeDuration
$dayTimeDuration-var
Time zone to add to $time-var as a duration. (Optional, if not specified the implicit time zone is used).

Returns

Returns a time without a time zone.

If $time-var does not contain a time zone and optional argument $dayTimeDuration-var is not specified, the passed in time is returned with no conversion.

Examples
Removing the Specified Timezone From a time Value

The following example removes the specified time zone from the specified time value.

In this example, the passed in time value: 12:00:00Z is specified with the UTC time zone as specified by the time zone indicator: Z.

The time zone is specified with the day Time Duration string: -PT7H, in the preceding query which is the Pacific Daylight Savings Time (PST) time zone (-07:00).

The passed in time value: 12:00:00Z specified with the UTC time zone is localized to PST time zone and the time zone indicator (Z) is removed, as shown in the following example query:

let $timeWithUTCTimezone := xs:time("12:00:00Z")

return

<components>

<timeWithUTCTimezone>{$timeWithUTCTimezone}</timeWithUTCTimezone>

<timeWithTimeZoneAdded>{ xf:remove-timezone-from-time(xs:time($timeWithUTCTimezone),

xf:dayTimeDuration("-PT7H")) }</timeWithTimeZoneAdded>

</components>

The preceding query produces the following result:

<components>

<timeWithUTCTimezone>12:00:00Z</timeWithUTCTimezone>

<timeWithTimeZoneAdded>05:00:00</timeWithTimeZoneAdded>

</components>

Removing the Implicit Timezone From the time Value

The following example removes the implicit time zone from the specified time value. In this example, the passed in time value: 12:00:00Z is specified with the UTC time zone as specified by the time zone indicator: Z.

In this example, the implicit time zone is assumed to be -07:00, the Pacific Daylight Savings Time (PST) time zone. (The implicit time zone is the default time zone for the current machine.)

The passed in time value: 12:00:00Z specified with the UTC time zone is localized to PST time zone and the time zone indicator (Z) is removed, as shown in the following example query:

let $timeWithUTCTimezone := xs:time("12:00:00Z")

return

<components>

<timeWithUTCTimezone>{$timeWithUTCTimezone}</timeWithUTCTimezone>

<timeWithTimeZoneAdded>{ xf:remove-timezone-from-time(xs:time($timeWithUTCTimezone)) }

</timeWithTimeZoneAdded>

</components>

The preceding query produces the following result:

<components>

<timeWithUTCTimezone>12:00:00Z</timeWithUTCTimezone>

<timeWithTimeZoneAdded>05:00:00</timeWithTimeZoneAdded>

</components>

Related Topics

W3C remove-timezone-from-time function description.

W3C time data type description.

W3C dayTimeDuration operator description.

 


xf: current-dateTime

Gets the current date and time.

Signatures

xf:current-dateTime() —> xs: dateTime?

Returns

Returns the current date and time as a date Time value.

All invocations of this function in a single outermost XQuery or XPATH expression will report the same date and time.

Examples
Invoke Once

The following simple example query, calls the current-dateTime function a single time:

<current>{xf:current-dateTime()}</current>

If the current date is November 11, 2002 and the current time is 4:23, the preceding XQuery generates the following result:

<current>2002-11-11T04:23:14.9030000</current>

Invoke Multiple Times

The following example query, invokes the current-dateTime function twice:

<current>

<first>{xf:current-dateTime()}</first>

<second>{xf:current-dateTime()}</second>

</current>

If the current date is November 11, 2002 and the current time is 4:23, the preceding XQuery generates the following result:

<current>

<first>2002-11-11T04:23:34.5430000</first>

<second>2002-11-11T04:23:34.5430000</second>

</current>

Note: The same exact time (even seconds) is returned for both invocations of the function.
Related Topics

W3C current-dateTime function description.

W3C dateTime data type description.

 


xf: current-date

Gets the current date.

Signatures

xf:current-date() —> xs: date?

Returns

Returns the current date as a date value.

All invocation of this function in a single outermost XQuery or XPATH expression will report the same date.

Examples

The following example query, invokes the current-date function:

<current>{xf:current-date()}</current>

If the current date is November 11, 2002 and the current time is 4:23, The preceding query generates the following result:

<current>2002-11-11</current>

Related Topics

W3C current-date function description.

W3C date data type description.

 


xf: current-time

Gets the current time.

Signatures

xf:current-time() —>xs: time?

Returns

Returns the current date and time as a time value.

All invocation of this function in a single outermost XQuery or XPATH expression will report the same time.

Examples
Invoke Once

The following example query, invokes the current-time function a single time:

<current>{xf:current-time()}</current>

If the current date is November 11, 2002 and the current time is 4:23, The preceding query generates the following result:

<current>04:23:14.9030000</current>

Invoke Multiple Times

The following example query, invokes the current-time function twice:

<current>

<first>{xf:current-time()}</first>

<second>{xf:current-time()}</second>

</current>

If the current date is November 11, 2002 and the current time is 4:23, The preceding query generates the following result:

<current>

<first>04:23:34.5430000</first>

<second>04:23:34.5430000</second>

</current>

Note: The same exact time (even seconds) is returned for both invocations of the function.
Related Topics

W3C current-time function description.

W3C time data type description.


  Back to Top       Previous  Next