0

I have a report designed in iReport with an integer field and it is displaying like:

End date

20171022
20170906
20170903

but I need to show this field in date format like:

22/10/2017
06/09/2017
03/09/2017

The 20171022 value at DB means the 22 October of 2017 date

Is there any way to do this?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Dayana
  • 1,500
  • 1
  • 16
  • 29
  • `20171022` - Are you sure that it is Integer, not the String? – Alex K Oct 25 '17 at 06:58
  • You can use SimpleDateFormat – Alex K Oct 25 '17 at 08:03
  • @AlexK yes, the field is an integer. – Dayana Oct 25 '17 at 13:08
  • I tried the answers in the other questions but some of them give an error: `The method X is not applicable for the arguments (Integer)` or give me a wrong date in the year 1970. This is the first time I'm using iReport, maybe I was doing something wrong. – Dayana Oct 25 '17 at 13:20
  • If you are storing the "22 November of 2017 year" date as Integer with 20171022 value - it is very unusual approach. If yes - I will remove duplicate flag, because in this case the solutions described at links are not working. Ping me in this case – Alex K Oct 25 '17 at 13:24
  • Yes, I don't know the reason but the value is storing like that: 20171022 for "22 October of 2017" – Dayana Oct 25 '17 at 13:27

1 Answers1

1

You can use below expression to achieve your desired result.

$F{column_name}.toString().substring(6,8) + "/" + $F{column_name}.toString().substring(4,6) + "/" + $F{column_name}.toString().substring(0,4)

You can handle the same inside your query. You just have to convert above expression as per your selected database.

Fahad Anjum
  • 1,246
  • 1
  • 10
  • 19