One month before today?



isn't there a easy way in iReports to calculate the date one month back from today? Without calculating with milliseconds... and correct date with longer/shorterr months...

In SQL it's so easy (DateAdd(mm,-1,getDate()) - thats it), but I need a field with the date I've used in the SQL-statement...

Any solutions out there?



toxy's picture
Joined: Sep 11 2006 - 7:34pm
Last seen: 6 years 8 months ago

3 Answers:


U can create a jar include ur own Date class. Then import it ireport. and use ur own class.

gocmenally's picture
Joined: Oct 3 2013 - 1:14am
Last seen: 6 years 10 months ago

thanks for the hint - I'll talk with our developer, perhapes he can include a ready made jar (calendar?)

toxy - 6 years 10 months ago

Perhapes I've just found another solution with readable code :-)

new Date().getMonth() in an integer-variable. Same for year and day, and calculating inside the variable expression (add or subtract days, month, years).

new Date().getYear() have to be added with 1900 to generate the current year (or subtract 100 for a two-digit year) - it's counting from 1900

But first tests gives a month one less the current, and a day one more than the current...? Hm, is there a counting too? how?...

christof, going on testing..

toxy's picture
Joined: Sep 11 2006 - 7:34pm
Last seen: 6 years 8 months ago

new SimpleDateFormat("MMMM").format(new"MONTH-1").toDateRange().getEnd())

That will give you the month name.

If you want a different thing you just have to change the format.



ferlim's picture
Joined: Oct 18 2019 - 7:57am
Last seen: 1 month 2 weeks ago