I\'ve a requirement to change the date format in iReport. Currently I used an SQL query to collect the data. Here\'s my query in iReport
SELECT DATE_F
To display dates in different formats, one option is to format dates based on locales. For example, the following expression uses the current user's locale:
DateFormat.getDateInstance(DateFormat.LONG, $P{REPORT_LOCALE}).format($F{currentDate})
You can create and use scriptlet or you can use expressions like in this samples:
ms_MY
, malaysia):<field name="currentDate" class="java.sql.Timestamp"/>
...
<textField>
<reportElement x="300" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[(new DateFormatSymbols(new Locale("ms", "MY")).getMonths())[$F{currentDate}.getMonth()]]]></textFieldExpression>
</textField>
? :
operator<field name="currentDate" class="java.sql.Timestamp"/>
...
<textField>
<reportElement x="200" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{currentDate}.getMonth() == 0 ?
"Januari" : $F{currentDate}.getMonth() == 1 ?
"Februari" : $F{currentDate}.getMonth() == 2 ?
"Mac" : $F{currentDate}.getMonth() == 3 ?
"April" : $F{currentDate}.getMonth() == 4 ?
"Mei" : $F{currentDate}.getMonth() == 5 ?
"Jun" : $F{currentDate}.getMonth() == 6 ?
"Julai" : $F{currentDate}.getMonth() == 7 ?
"Ogos" : $F{currentDate}.getMonth() == 8 ?
"September" : $F{currentDate}.getMonth() == 9 ?
"Oktober" : $F{currentDate}.getMonth() == 10 ?
"November" : $F{currentDate}.getMonth() == 11 ?
"Disember" : "Unknown"
]]></textFieldExpression>
</textField>