Milliseconds since 1970 in XPath 2.0

Here's a quick way to obtain the number of milliseconds since January 1st 1970 of any date in XPath 2.0.

If your variable contains a date in the format of xs:date (YYYY-MM-DD), then you can use:

(xs:date($myvar) - xs:date('1970-01-01'))
  div xs:dayTimeDuration('PT0.001S')

If your variable contains a date in the format of xs:dateTime, then you can use:

(xs:dateTime($myvar) - xs:dateTime('1970-01-01T00:00:00'))
  div xs:dayTimeDuration('PT0.001S')

Based on this FAQ entry.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options