Get the next day of a date
Returns the next date from a given date
Description
This snippet returns the next day.
Leap year (29.04.2012) calculation is not implemented.
XSLT
View Raw
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template name="next-day-date"> <xsl:param name="date"/> <!-- format is YYYY-MM-DD --> <xsl:variable name="old_year" select="substring($date, 1, 4)"/> <xsl:variable name="old_month" select="substring($date, 6, 2)"/> <xsl:variable name="old_day" select="substring($date, 9, 2)"/> <xsl:variable name="year"> <xsl:choose> <xsl:when test="$old_month='12' and $old_day='31'"> <xsl:value-of select="$old_year+1"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$old_year"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="month"> <xsl:choose> <xsl:when test="$old_day='31'"> <xsl:choose> <xsl:when test="$old_month='01' or $old_month='03' or $old_month='05' or $old_month='07' or $old_month='08'"> <xsl:text>0</xsl:text> <xsl:value-of select="$old_month+1"/> </xsl:when> <!-- october --> <xsl:when test="$old_month='10'"> <xsl:value-of select="$old_month+1"/> </xsl:when> <!-- december it is --> <xsl:when test="$old_month='12'"> <xsl:text>01</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$old_month"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:when test="$old_day='30'"> <xsl:choose> <xsl:when test="$old_month='04' or $old_month='06' or $old_month='09'"> <xsl:text>0</xsl:text> <xsl:value-of select="$old_month+1"/> </xsl:when> <!-- november --> <xsl:when test="$old_month='10'"> <xsl:value-of select="$old_month+1"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$old_month"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:when test="$old_day='28' and $old_month='02'"> <xsl:text>03</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$old_month"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="day"> <xsl:choose> <xsl:when test="$old_month!=$month"> <xsl:text>01</xsl:text> </xsl:when> <xsl:when test="number($old_day) < 9"> <xsl:text>0</xsl:text> <xsl:value-of select="$old_day+1"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$old_day+1"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:value-of select="$year"/> <xsl:text>-</xsl:text> <xsl:value-of select="$month"/> <xsl:text>-</xsl:text> <xsl:value-of select="$day"/> </xsl:template> </xsl:stylesheet>