Subject: Re: Computing Number of Days between Two Dates in XSLT 1.0
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Thu, 15 Feb 2007 22:28:53 +0530
|
I think you will be pleased to know, that these kind of operations
have become much simpler with XSLT 2.0.
The following is equivalent XSLT 2.0 code:
<xsl:variable name="date1" select="xs:date('2000-02-25')" />
<xsl:variable name="date2" select="xs:date('2007-05-26')" />
<xsl:value-of select="$date2 - $date1" />
(where xs is bound to namespace URI http://www.w3.org/2001/XMLSchema)
On 2/15/07, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
I just now tried the EXSLT date:difference template (after downloading
date.difference.zip from
http://www.exslt.org/date/functions/difference/index.html), and it
seems to work as you want.
I tried this code:
<xsl:variable name="date1" select="'2000-02-25'" />
<xsl:variable name="date2" select="'2007-05-26'" />
<xsl:call-template name="date:difference">
<xsl:with-param name="start" select="$date1" />
<xsl:with-param name="end" select="$date2" />
</xsl:call-template>
I get the answer -> P2646D
I always get the answer in number of days (I tried with different
dates). I think, this is what you want.
On 2/15/07, Roger L. Cauvin <roger@xxxxxxxxxx> wrote:
> I am looking for an XSLT 1.0 template that computes the number of days
> between two dates. I don't want to reinvent the wheel, but I was unable to
> find such a template browsing around in Google. Can anyone post or point me
> to one?
>
> I know there is an EXSLT date:difference template that computes the duration
> between two dates, but it can include years and months. It is not a trivial
> task converting these components of a duration to the number of days, as I
> would have to take into account leap years and the different number of days
> in each month.
>
> --
> Roger L. Cauvin
> r o g e r @ c a u v i n . o r g
> http://cauvin.blogspot.com
--
Regards,
Mukul Gandhi
|