Is there any way in XQuery to get the current time in milliseconds since some Epoch?

jbx picture jbx · Sep 20, 2011 · Viewed 16.7k times · Source

XQuery offers various date/time functions like current-dateTime(), however I can't seem to find one which gives me the time in milliseconds since Epoch. Functions to extract hours, minutes and seconds seem to exist too individually.

What is the right way to get the Epoch time (i.e. unix time or similar) in XQuery?

Answer

Michael Kay picture Michael Kay · Sep 20, 2011
(current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xs:dayTimeDuration('PT0.001S')

returns the number of seconds as a duration, and then divides by 1 millisecond to get the number of milliseconds as a number.