I try to compare two dates with format yyyy-MM-ddTHH:mm:ss
in a thymeleaf template.
I am able to compare a date, when I try:
${#dates.createNow().before(#dates.createNow())} // =false - just as an example
But my case is a bit tricky. At first I parse a string to obtain a date:
<th:block th:with="sdf = ${new java.text.SimpleDateFormat('yyyy-MM-dd''T''HH:mm:ss')}, isodate = ${isodate}, isodatemod = ${isodateModified}" >
Then I compare it:
<p th:switch="${#dates.format(sdf.parse(isodate)).before(#dates.format(sdf.parse(isodatemod)))}" />
This reveals the following error statement:
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#dates.format(sdf.parse(isodatemod)).before(#dates.format(sdf.parse(isodatemod)))
[...]
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method before(java.lang.String) cannot be found on type java.lang.String
I just don't see, why after parsing my date, it is still seen as string? Is there any way to make these two dates comparable in thymeleaf?
I use the following import:
implementation group:"org.springframework.boot", name:"spring-boot-starter-thymeleaf"