Default values for date parameters


Hi guys,

I have startdate and enddate parameters . I should give the default vaules explained below.

Date range should be last half(1/2) month.

1 to 15 when run from 16th onwords

16 to 31 when run from from 1st until the 15th

More clearly:

If today is 2013-10-07 then startdate is : 2013-09-16 enddate is : 2013-09-31

if today is : 2013-10-23 then startdate is : 2013-10-01 enddate is: 2013-10-15

The same logic should applicable in january month as well(i.e, for instance if today is : 2013-01-13 then startdate: 2012-12-16 enddate:2012-12-31)

How to write this logic in default expressions using java/javascript/groovy script  for startdate and enddate parameters ?


Many thanks in Advance :)



sadakar's picture
Joined: Aug 14 2012 - 3:57am
Last seen: 8 hours 8 min ago

2 Answers:


Attached is a sample report (DatesStandard.JRXML) that will give you some pointers on how to do this. As you said you need to write the expressions to initialize those parameters in Java or Groovy. Check my deafult expressions for my date to / from parameters in the attached sample.

The .ZIP file that I attached is a JasperServer Repository export of the same report so you can add it to your server and see how it works form there the report will be put into /public/sandbox/demos/Standard Dates

Another method you can use is to use is to use the JRS relative dates classes to allow the use of keywords to identify date ranges for this method see the DatesRelativeSample.jrxml attached


marianol's picture
Joined: Sep 13 2011 - 8:04am
Last seen: 2 years 8 months ago

Thank you

sadakar - 7 years 8 months ago

This was really helpful! I couldn't switch my particular report to Groovy though. I had to stick with Java.  Java didn't like the .set and .get methods returning void so I used a different approach:

To get the fiscal year start date:

TODAY().getMonth() < 6 ?

java.sql.Date.valueOf(Calendar.getInstance().get(Calendar.YEAR) - 1 + "-07-01")


java.sql.Date.valueOf(Calendar.getInstance().get(Calendar.YEAR) + "-07-01")


To get the fiscal year end date:

TODAY().getMonth() < 6 ?

java.sql.Date.valueOf(Calendar.getInstance().get(Calendar.YEAR) + "-06-30")


java.sql.Date.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 1 + "-06-30")

tj.tripp - 1 year 5 months ago
sadakar's picture
Joined: Aug 14 2012 - 3:57am
Last seen: 8 hours 8 min ago