JSTL Date comparison

Nati picture Nati · Sep 13, 2012 · Viewed 31.5k times · Source

I've seen some posts about date comparisons in JSTL, but I still can't get it to work.

I have a date field, which I want to test whether is after 01-01-1970.

<c:if test="${user.BirthDate > whatGoesHere}">
    <doSomeLogic/>
</c:if>

Maybe a bean should be used?

Thanks !

Answer

BalusC picture BalusC · Sep 13, 2012

Just use <fmt:formatDate> to extract the year from it so that you can do the math on it.

<fmt:formatDate value="${user.birthDate}" pattern="yyyy" var="userBirthYear" />
<c:if test="${userBirthYear le 1970}">
    <doSomeLogic/>
</c:if>