1

I have a string file FECHA EMISION="2018-03-02". I want it to display as "Marzo" (March in Spanish/Italian).

I have to convert $F{FECHA EMISION}.substring(5,7) in integer, but I don´t know how convert the result 02 to the related month.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Mayca
  • 29
  • 2

2 Answers2

0

Try setting this expression to a textField:

DATEFORMAT(new SimpleDateFormat("yyyy-MM-dd").parse($F{FECHA EMISION}), "MMMMM")
Narcis
  • 2,421
  • 4
  • 16
  • 23
  • I'm surprise the you don't suggest the use of pattern (that will keep original data if you export to eg excel), so I have posted a competing answer :P – Petter Friberg Jan 29 '19 at 20:41
  • Why keep the date when it was a string originally? – Narcis Jan 30 '19 at 09:00
  • Because it's incorrectly a String, it should have been a Date :), anyway not much difference. – Petter Friberg Jan 30 '19 at 11:20
  • This option work correctly. Thanks – Mayca Jan 30 '19 at 18:42
  • But i want to print "MARZO", i mean, the option before give me marzo like a date. I have to convert it to string and then apply touppercase() but i don´t know the nomenclature for this – Mayca Jan 30 '19 at 18:48
  • The correct expression is UPPER(DATEFORMAT(new SimpleDateFormat("yyyy-MM-dd").parse($F{FECHA EMISION}), "MMMMM")). It shows MARZO. – Mayca Jan 30 '19 at 19:29
  • Once you have the month name you are in control of its formatting. – Narcis Jan 30 '19 at 19:40
0

The best way to do this is to have a Date object and then apply a pattern (pattern will allow you to export original data to e.g. excel while displaying it as you like)

To apply a pattern you will need to transform the String into a Date object

new java.text.SimpleDateFormat("yyyy-MM-dd").parse($F{FECHA EMISION})

The pattern is MMMM see Date and Time Patterns

So the final jrxml will be

<textField pattern="MMMM">
   <reportElement x="0" y="0" width="100" height="30"/>
    <textFieldExpression><![CDATA[new java.text.SimpleDateFormat("yyyy-MM-dd").parse($F{FECHA EMISION})]]></textFieldExpression>
</textField>

Note: In JasperSoft Studio pattern is a property of the textField, hence you can indicate this directly in Studio.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109