Name

[2.0] dateTime()

This is a special constructor function that lets you create an xs:dateTime value from an xs:date and xs:time.

Syntax

xs:dateTime? dateTime(xs:date?, xs:time?)

Inputs

An xs:date value and an xs:time value.

Output

A new xs:dateTime value based on the two input values. If either input value is the empty sequence, xs:dateTime() returns the empty sequence. The timezone of the xs:dateTime result is calculated as follows:

  • If neither argument has a timezone, the result does not have a timezone.

  • If one of the arguments has a timezone or if both arguments have the same timezone, the result has that timezone.

  • If the two arguments have different timezones, the XSLT processor raises an error.

Defined in

XQuery 1.0 and XPath 2.0 Functions and Operators section 5, “Constructor Functions.”

Example

This stylesheet uses the values from the current-date() and current-time() functions to create a new xs:dateTime value:

<?xml version="1.0"?>
<!-- datetime.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>&#xA;Creating an xs:dateTime with an </xsl:text> <xsl:text>xs:date and xs:time:</xsl:text> <xsl:variable name="currentDate" as="xs:date" select="current-date()"/> <xsl:variable name="currentTime" as="xs:time" select="current-time()"/> <xsl:text>&#xA;&#xA; The current date is: </xsl:text> <xsl:value-of select="$currentDate"/> <xsl:text>&#xA;&#xA; The ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.