Discussion:
xsl date format
(too old to reply)
m***@cscworld.com
2006-07-21 12:25:15 UTC
Permalink
xsl newbie question: I don't seem to be able to find a simple function
to convert a date in DD/MM/YY format to an integer since Epoch. I have
the DD/MM/YY value in one mySQL database and trying to dump the data
into another database - the app that's using the second database
requires the date to be an integer.

Surely this is a fairly common requirement to transform dates to and
from the integer value?
Joe Kesselman
2006-07-21 13:33:02 UTC
Permalink
Post by m***@cscworld.com
Surely this is a fairly common requirement to transform dates to and
from the integer value?
Common application requirement, but not a common stylesheet requirement,
so it isn't part of XSLT 1.0. (I'm not sure whether 2.0, which does more
with datatypes, adds it.)

Personally, I'd say it's time to investigate your XSLT processor's
support for extension functions. If you're using Xalan-J, for example,
it's not hard to invoke the Java date support. Downside is that
extension functions are nonportable (or, in the case of the EXSLT
semi-standard, only semi-portable) since they aren't part of the XSLT
standard.
Martin Honnen
2006-07-21 14:11:11 UTC
Permalink
Post by m***@cscworld.com
xsl newbie question: I don't seem to be able to find a simple function
to convert a date in DD/MM/YY format to an integer since Epoch. I have
the DD/MM/YY value in one mySQL database and trying to dump the data
into another database - the app that's using the second database
requires the date to be an integer.
XSLT/XPath 1.0 does not have any date data type.

XSLT/XPath 2.0 uses the XSD schema types which have a format like
YYYY-MM-DD (plus the possibility for time zone information). There is a
substraction operator '-' defined on the date data type so you can do e.g.
xsd:date('2006-05-09') - xsd:date('1970-01-01')
which gives you a value of type duration from which you can extract the
number of days, hours, minutes, seconds with functions like
days-from-duration(xsd:date('2006-05-09') - xsd:date('1970-01-01'))
That way you can implement a function that converts the duration into
seconds.
--
Martin Honnen
http://JavaScript.FAQTs.com/
Loading...