Hi Kenneth,
Using some functions from our datetime_lib.xsl (
www.marrowsoft.com -
libraries included in the trial installer) you could do...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="unix_timestamp" select="875996580"/>
<xsl:variable name="jd19700101" select="2440588"/>
<xsl:call-template name="float-to-date-time">
<xsl:with-param name="value" select="$jd19700101 + ($unix_timestamp div
(24 * 60 * 60))"/>
</xsl:call-template>
</xsl:template>
<!--
================================================== ========================
Template: float-to-date-time
Description: Convert a floating point value representing a date/time to
a date/time string.
Parameters:-
<value> the value to be converted
<round-seconds> if true then the seconds are not quoted on the output
and, if the seconds are 59 then hour/minute is rounded
(this is useful because some processors have limited
floating point precision to cope with the seconds)
================================================== ======================== -
->
<xsl:template name="float-to-date-time">
<xsl:param name="value" select="number(0)"/>
<xsl:param name="round-seconds" select="false()"/>
<xsl:variable name="date">
<xsl:call-template name="julian-day-to-date">
<xsl:with-param name="julian-day" select="floor($value)"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="t1" select="$value - floor($value)"/>
<xsl:variable name="h" select="floor($t1 div (1 div 24))"/>
<xsl:variable name="t2" select="$t1 - ($h * (1 div 24))"/>
<xsl:variable name="m" select="floor($t2 div (1 div 1440))"/>
<xsl:variable name="t3" select="$t2 - ($m * (1 div 1440))"/>
<xsl:choose>
<xsl:when test="$round-seconds">
<xsl:variable name="s" select="$t3 div (1 div 86400)"/>
<xsl:variable name="h2">
<xsl:choose>
<xsl:when test="($s >= 59) and ($m = 59)"><xsl:value-of select="$h +
1"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$h"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="m2">
<xsl:choose>
<xsl:when test="($s >= 59) and ($m = 59)">0</xsl:when>
<xsl:when test="($s >= 59)"><xsl:value-of select="$m +
1"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$m"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- pad final time result -->
<xsl:variable name="hh" select="concat(substring('00',1,2 -
string-length(string($h2))),string($h2))"/>
<xsl:variable name="mm" select="concat(substring('00',1,2 -
string-length(string($m2))),string($m2))"/>
<!-- final output resultant -->
<xsl:value-of select="concat($date,'T',$hh,':',$mm)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="s" select="floor($t3 div (1 div 86400))"/>
<!-- pad final time result -->
<xsl:variable name="hh" select="concat(substring('00',1,2 -
string-length(string($h))),string($h))"/>
<xsl:variable name="mm" select="concat(substring('00',1,2 -
string-length(string($m))),string($m))"/>
<xsl:variable name="ss" select="concat(substring('00',1,2 -
string-length(string($s))),string($s))"/>
<!-- final output resultant -->
<xsl:value-of select="concat($date,'T',$hh,':',$mm,':',$ss)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
================================================== ========================
Template: julian-day-to-date
Description: Convert a julian day to date
Parameters:-
<julian-day>
================================================== ======================== -
->
<xsl:template name="julian-day-to-date">
<xsl:param name="julian-day" select="number(0)"/>
<!-- pre-calcs -->
<xsl:variable name="la" select="$julian-day + 68569"/>
<xsl:variable name="n" select="floor((4 * $la) div 146097)"/>
<xsl:variable name="lb" select="$la - floor((146097 * $n + 3) div 4)"/>
<xsl:variable name="i" select="floor((4000 * ($lb + 1)) div 1461001)"/>
<xsl:variable name="lc" select="$lb - floor((1461 * $i) div 4) + 31"/>
<xsl:variable name="j" select="floor((80 * $lc) div 2447)"/>
<xsl:variable name="day" select="$lc - floor((2447 * $j) div 80)"/>
<xsl:variable name="ld" select="floor($j div 11)"/>
<xsl:variable name="month" select="$j + 2 - (12 * $ld)"/>
<xsl:variable name="year" select="100 * ($n - 49) + $i + $ld"/>
<!-- whole days -->
<xsl:variable name="iday" select="floor($day)"/>
<!-- pad final result -->
<xsl:variable name="sday" select="concat(substring('00',1,2 -
string-length(string($iday))),string($iday))"/>
<xsl:variable name="smonth" select="concat(substring('00',1,2 -
string-length(string($month))),string($month))"/>
<xsl:variable name="syear" select="concat(substring('00',1,4 -
string-length(string($year))),string($year))"/>
<!-- final output -->
<xsl:value-of select="concat($syear,'-',$smonth,'-',$sday)"/>
</xsl:template>
</xsl:stylesheet>
Cheers
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Thomas" <ridder_dk@SLET_DETTEhotmail.com> wrote in message
news:7R**********************@news010.worldonline. dk...
And what's its meaning (e.g. number of seconds after some date)?
Source: http://www.mysql.com/doc/en/Date_and...functions.html
It would be a lot easier if they pull the data out of the database as a
readable date instead of unix timestamp, but they don't. :(
Regards,
Kenneth