Altova Mailing List Archives
>xsl-list Archive Home
>Recent entries
>Thread Prev -
>Thread Next - Re: [xsl] Problem with date:add
[xsl] Problem with date:add
To:
Date: 2/15/2006 10:19:00 AM
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
Disclaimer
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

