Note that there are some explanatory texts on larger screens.

plurals
  1. POxslt: time ago test
    primarykey
    data
    text
    <p>using xslt how do i test if a date was within the last (say) 15 days? </p> <p>input:</p> <ul> <li>date in format dd/mm/yy</li> <li>X number of days</li> </ul> <p>output:</p> <ul> <li>if the date occured within X days of now</li> </ul> <p>eg recent('02/07/10',30) would return true iff 02/07/10 was 30 days in the past</p> <p>some steps i got:</p> <p>main func</p> <pre><code> &lt;xsl:function name="custom:monthtodays"&gt; &lt;xsl:param name="date"/&gt; &lt;xsl:param name="daysago"/&gt; &lt;xsl:variable name="daycountnow" select="year-from-dateTime(current-dateTime())*365+day-from-dateTime(current-dateTime())+custom:monthtodays(month-from-dateTime(current-dateTime())" /&gt; &lt;xsl:variable name="datedaycount" select="numeric(substring($date,1,2))+numeric(substring($date,7,2))*365+custom:monthtodays(numeric(substring($date,4,2)))" /&gt; &lt;xsl:value-of select="$daycountnow - $datedaycount - $daysago &gt; 0"/&gt; &lt;/xsl:function&gt; </code></pre> <p>helper func</p> <pre><code> &lt;xsl:function name="custom:monthtodays"&gt; &lt;xsl:param name="month"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$month =1"&gt; &lt;xsl:value-of select="0"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =2"&gt; &lt;xsl:value-of select="31"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =3"&gt; &lt;xsl:value-of select="59"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =4"&gt; &lt;xsl:value-of select="90"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =5"&gt; &lt;xsl:value-of select="120"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =6"&gt; &lt;xsl:value-of select="151"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =7"&gt; &lt;xsl:value-of select="181"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =8"&gt; &lt;xsl:value-of select="212"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =9"&gt; &lt;xsl:value-of select="243"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =10"&gt; &lt;xsl:value-of select="273"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =11"&gt; &lt;xsl:value-of select="304"/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$month =12"&gt; &lt;xsl:value-of select="334"/&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:function&gt; </code></pre> <p>but this doesnt take account of leap years and the like ... surely there is a betterway?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload