Showing remaining days
This is an open discussion with 5 replies, filed under XSLT.
Search
Have you already tried EXSLT? It should be available on most hosting environments. There are some cool date/time functions in EXSLT.
Your opening stylesheet tag will look like this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
Then you can do things like this (which is just an example):
<xsl:if test="date:seconds(date:difference(date:date-time(), '2009-07-12T15:00:00+01:00')) > '0'"> ...
I believe EXSLT will always be available with libXSL.
michael-e is spot on. I do a similar thing in the Time Ago utility which calculates the number of minutes between two dates.
In what format is the “period” stored (days, weeks, years etc?)
The subscribe date is stored like: 30 August 2010 22:49
The period format is stored as months, for example: 3 (for 3 months)
In which I guess you want to add on n
months to subscribe-date
and then compare with the current date?
Something like this
<xsl:variable name="subscribe-date" select="'2010-08-30T22:49:00'"/> <xsl:variable name="subscribe-period" select="'3'"/> <xsl:variable name="expiry-date" select="date:add($subscribe-date, concat('P', $subscribe-period, 'M'))"/>
(duration syntax P3M
explained here)
You should then be able to compare the expiry date by the current date (as michael-s suggests) to get the number of seconds, then convert this to days.
Thank you all, now I’m very happy :)
Another question, is it possible to change the status of the subscription after the expiry date is reached?
Create an account or sign in to comment.
Hello,
I hope someone can assist me with this.
Members can subscribe themselves and take the subscription for a period. When they are subscribed the subscription date is stored at a section same with the period.
Now I want to show the remaining days of the subscription with XSLT, but how can I do that?