I’ve recently come across development requires date comparison before populating the items.
This cannot be done directly through XPATH query through comparative operator accept “=” and “!=”, syntax like “>”, “<” and etc doesn’t work as expected.
Thus the workaround is to convert the DateTime string to number and removing any symbol usually found in DateTime format. Exp: “-”, “/”.
Example
| Normal DateTime format |
| = 2009-07-21T00:34:16Z |
| After conversion |
| code: number(translate(substring(@StartDate,1,10),'-','')) |
| = 20090721 |
| Compare DateTime |
| <xsl:if test="number(translate(substring(@StartDate,1,10),'-','')) > number(translate(substring(@EndDate,1,10),'-','')) "> …. </xsl:if> |
There you go, a simple way to compare DateTime in XSLT.
Credit goes to Kode's thoughts