I want to compare two dates using Struts2
One is returned from the backend (test.currentDate) == "2012-11-15)"
The other one I just set "2014-10-19"
How can I compare the two dates?
My code is as follows:
<s:set name="currentDate" value="%{test.currentDate}"/>
<s:set name="futureDate" value="2014-10-19"/>
<s:if test="%{#currentDate.before(#futureDate)}">
<s:text name="test"/> <s:date name="test.currentDate" format="MM/yy"/>
</s:if>
<s:else>
<s:text name="test2"/>
</s:else>
In the above you were trying compare string with date object that’s causing the problem.
I suggest you to write a helper class to compare date and take the advantage of OGNL static method access. OGNLBasics-Accessingstaticproperties
Util Class