Subject: [xsl] Problem with date:add From: "Andrew Smith" <andrew.smith@xxxxxxxxxxxxx> Date: Wed, 15 Feb 2006 10:18:24 -0000 |
Hi, I was looking for a way to easily check if a date was less than 30 days old using XSLT and came across http://www.exslt.org which had several useful date templates, however, none of them seem to do what I'd like. My initial thought would be to use date:difference, if the difference was more than 30 then I'd know it was an 'old' date, otherwise it'd be a 'new' date. However, it doesn't work quite like I'd expect since (as shown below) it doesn't return the 'correct' values (I know this is by design from reading the page). <xsl:call-template name="date:difference"> <xsl:with-param name="start">2006-02-10T15:38:00</xsl:with-param> <xsl:with-param name="end">2006-02-08T15:38:00</xsl:with-param> </xsl:call-template> would return '-P2D' and (notice the end date is now in January not February) <xsl:call-template name="date:difference"> <xsl:with-param name="start">2006-02-10T15:38:00</xsl:with-param> <xsl:with-param name="end">2006-01-08T15:38:00</xsl:with-param> </xsl:call-template> would also return '-P2D' where what I'd expect is '-P33D' or '-P1M2D' <xsl:call-template name="date:difference"> <xsl:with-param name="start">2006-02-10T15:38:00</xsl:with-param> <xsl:with-param name="end">2006-01-31T15:38:00</xsl:with-param> </xsl:call-template> then returns 'P21D' and not '-P11D'. So my next attempt was to use date:add and 'add' -30 days, however, this also doesn't work, resulting in a time out. This is because it doesn't support date roll overs (i.e. reaching the start/end of one month doesn't move on to the end/start of the next month) and so <xsl:variable name="thirtyDaysAgo"> <xsl:call-template name="date:add"> <xsl:with-param name="date-time" select="2006-02-10T15:38:00" /> <xsl:with-param name="duration">-P30D</xsl:with-param> </xsl:call-template> </xsl:variable> causes the crash and <xsl:variable name="thirtyDaysAgo"> <xsl:call-template name="date:add"> <xsl:with-param name="date-time" select="2006-02-10T15:38:00" /> <xsl:with-param name="duration">P30D</xsl:with-param> </xsl:call-template> </xsl:variable> returns '2006-32-10T15:38:00' So, after all of this, my question to the list is, is there an easy way to see if a stored date is less than 30 days old, either using these templates or any other templates. Thanks for any help Andy
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to use & in CDATA field, viniciuscamara | Thread | Re: [xsl] Problem with date:add, Mukul Gandhi |
Re: [xsl] possible nested loops, George Cristian Bina | Date | Re: [xsl] Problem with date:add, Mukul Gandhi |
Month |