Skip to main content
Windward

Compare date

Overview

If you're having trouble comparing dates, here's an answer I posted in the forums for checking if a date is equal to another date, or if a date is greater than/less than a particular date.

Resolution

When you just want to see if one date is equal to another, then you can use something like this:

<wr:query select="/Order/Date" var="d" datasource="car"/>
<wr:if select="${d}[@oldValue =&apos;1990-10-18&apos;]" datasource="car">
true
</wr:if>

This is a good way to do it if you're iterating through records using a foreach as well.

 

If you want to compare date ranges using greater than and less than, then you can use something like this:

<wr:out select="number(translate(/Order/Date/@oldValue,&quot;-&quot;,&quot;&quot;)) &lt; number(translate(/Order/Date,&quot;-&quot;,&quot;&quot;))" display="false" var="t" datasource="car"/>

<wr:if test="${t}" datasource="car">

true

<wr:else/>false
</wr:if>

As things stand, the if tag doesn't handle date comparisons for greater than and less than (xml), so instead we use xpath functions (number and translate) in the out tag and use the out tag's variable ('t' in the example) to check the result.  The out tag in the example has display="false" so that it doesn't print the result.

  • Was this article helpful?