Jump to content
We've recently updated our Privacy Statement, available here ×

Default values for date parameters


sadakar

Recommended Posts

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

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

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

 

Link to comment
Share on other sites

  • 6 years later...

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")

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...