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...
Try this:
new SimpleDateFormat("MM/dd/yyyy").format($F{BANK_DATE})
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With