GetDay (), getMonth (), getYear ()

I have a timestamp textField called $ F {Fecha}, and I want to get the day, month and year from it. I created 3 variables var1, var2, var3 and in my expressions I set the following $ F {Fecha} .getDay (), $ F {Fecha} .getMonth (), $ F {Fecha} .getYear (); this gives me a value in return, but they are incorrect values, that is, if my date is 20120118, it returns me day = 3, month = 0, year = 112.

How can i fix this? Thanks in advance.

PD. I am using iReport 4.0.0

+4
source share
3 answers

Me and Alex: parsing a string to output date information is a bad idea. For example: run the report using a different language, and you will find that your report is breaking unexpectedly.

Java does not have very good date processing built in for this purpose. But you can use Joda-Time or Apache Commons Lang to get a bunch of useful features.

+1
source

Here is a way to do this using Java expressions:

day: new Integer ($ F {Fecha} .getDate ())

Month: new Integer ($ F {Fecha} .getMonth () + 1)

Year: new Integer ($ F {Fecha} .getYear () + 1900)

+1
source

If possible, you can do this in SQL.

MySQL has the MONTH (), DAY (), and YEAR () functions that will do this.

0
source

Source: https://habr.com/ru/post/1392832/


All Articles