Search code examples
jstljsp-tagsjava.util.date

JSTL Date comparison


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 !


Solution

  • 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>