Search code examples
jasper-reports

How to compare dates for conditional formatting?


I am trying to create conditional style for JasperReport's report and I need to compare date with current date if not null or blank. I have tried with several ways but no luck till now. Please suggest what is wrong in below condition.

(($F{ORDER_BY_DATE} != " ") && ($F{ORDER_BY_DATE} != null)) ?
    ((new Date().after(new Date($F{ORDER_BY_DATE}))) ? true : false) :
 false

I'm using iReport 5.6.0


Solution

  • I've not tested it, but I would change your code just by seeing it to this:

    $F{ORDER_BY_DATE} != null && !$F{ORDER_BY_DATE}.trim().isEmpty() && new Date().after(new Date($F{ORDER_BY_DATE}))
    
    • trim() removes all spaces at the begin & end of the string
    • isEmpty() is equal to .length == 0

    Maybe this solves your problem