Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date formatting part of text in Jasper / ireports

how do I format a date field (database field) displayed part of a text in Jasper / iReports (4.5.1)

Displayed via a text field in the report... (using Groovy please)

"Sub total for this date: " + $F(DEPOSIT_DATE)

I have tried (new SimpleDateFormat("MM/dd/yyyy")).parse($F{DEPOSIT_DATE})and I am getting error message:

net.sf.jasperreports.engine.fill.JRExpressionEvalException: 
Error evaluating expression : Source text : (new SimpleDateFormat("MM/dd/yyyy")).parse($F{BANK_DATE}) 

What I want to display in my report is as follows...

Sub total for this date: MM/DD/YYYY - format...

like image 267
Meeza S Avatar asked Dec 01 '25 13:12

Meeza S


2 Answers

Try this:

new SimpleDateFormat("MM/dd/yyyy").format($F{BANK_DATE})
like image 103
Meeza S Avatar answered Dec 03 '25 07:12

Meeza S


I agree with Mateusz, textField with pattern perfrormes faster than new SimpleDateFormat("someFormat").format("jasperField"). It's important when you have deal with huge reports. This is my example

<textField pattern="MM/dd/yyyy" isBlankWhenNull="true">
...
    <textFieldExpression class="java.util.Date"><![CDATA[$F{certIssueDate}]]></textFieldExpression>
</textField>
like image 30
Valeriy Gorbatikov Avatar answered Dec 03 '25 06:12

Valeriy Gorbatikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!