Search code examples
xsltxslt-2.0saxon

How to compare 2 dates


I know this question might get repeated and i am still learning (XML-XSLT : How to compare two dates which are in String)

EX:<oldDate>2019-09-25T10:49:52.755Z</oldDate> <currentDate>2019-07-25T10:49:52.755Z</currentDate>

can some one help me sample code: XML-XSLT : How to compare two dates which are in String

EXPECTED output: <?xml version="1.0" encoding="utf-8"?> <xml> <output>OK</output> </xml>

or

<?xml version="1.0" encoding="utf-8"?> <xml> <output>Not Ok</output> </xml>

Please someone help me to compare this kind of date format


Solution

  • You can simply use below code after typecast the string as date xs:dateTime():

    <xsl:value-of select="if (xs:dateTime(/root/oldDate) > xs:dateTime(/root/currentDate)) then ('OK') else ('Not OK')"/>
    

    see this link: https://xsltfiddle.liberty-development.net/bnnZX6