Comparing Dates
This is an open discussion with 3 replies, filed under General.
Search
Take a look at these templates:
https://github.com/hananils/kit/blob/master/datetime.xsl#L363-L390.
https://github.com/hananils/kit/blob/master/datetime.xsl#L415-L428
There's also this small utility, in case you need an extra check on the validity/compliance of a date.
Thanks guys, i had another approach. Not sure if its the best one however its been working.
<xsl:variable name="today-date" select="number(translate(substring(date:date(),1,10),'-',''))"/> <!-- First trimester --> <xsl:variable name="start-of-year-1" select="number(translate(substring(date:date(concat($this-year, '-01-01')),1,10),'-',''))"/> <xsl:variable name="end-of-year-1" select="number(translate(substring(date:date(concat($this-year, '-03-30')),1,10),'-',''))"/> <!-- Second trimester --> <xsl:variable name="start-of-year-2" select="number(translate(substring(date:date(concat($this-year, '-04-01')),1,10),'-',''))"/> <xsl:variable name="end-of-year-2" select="number(translate(substring(date:date(concat($this-year, '-06-30')),1,10),'-',''))"/> <!-- Third Trimester --> <xsl:variable name="start-of-year-3" select="number(translate(substring(date:date(concat($this-year, '-07-01')),1,10),'-',''))"/> <xsl:variable name="end-of-year-3" select="number(translate(substring(date:date(concat($this-year, '-12-31')),1,10),'-',''))"/> <xsl:variable name="percentage"> <xsl:choose> <xsl:when test="$url-shop != 'yes' and $today-date >= $start-of-year-1 and $today-date <= $end-of-year-1">0.75</xsl:when> <xsl:when test="$url-shop != 'yes' and $today-date >= $start-of-year-2 and $today-date <= $end-of-year-2" >0.50</xsl:when> <xsl:when test="$url-shop != 'yes' and $today-date >= $start-of-year-3 and $today-date <= $end-of-year-3">1</xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:variable>
Create an account or sign in to comment.
Hey guys,
What would be the easiest way to compare dates using xslt?
I've got for example today date and i want to check if the date falls between 2 dates?!
Example:
Thanks all, Andre.