XQuery current-dateTime()
In XQuery, the fn:current-dateTime()
function is used to retrieve the current date and time as an xs:dateTime
value. This function does not take any arguments and returns the current date and time in the local time zone of the system on which the XQuery is executed.
The xs:dateTime
data type represents a date and time value in the format “YYYY-MM-DDThh:mm:ss.sss”, where “YYYY” is the year, “MM” is the month (01 to 12), “DD” is the day (01 to 31), “hh” is the hour (00 to 23), “mm” is the minute (00 to 59), “ss” is the second (00 to 59), and “sss” is the fractional seconds.
Here’s an example of using fn:current-dateTime()
in XQuery:
let $currentDateTime := fn:current-dateTime()
return $currentDateTime
Output:
2023-07-27T13:45:21.345
In this example, the variable $currentDateTime
is assigned the current date and time when the XQuery is executed. The output will display the current date and time in the “YYYY-MM-DDThh:mm:ss.sss” format.
Please note that the value returned by fn:current-dateTime()
can vary depending on the system’s clock and time zone settings. If you need to obtain only the current time or date separately, you can use fn:current-time()
or fn:current-date()
functions, respectively.