sadakar Posted October 7, 2013 Share Posted October 7, 2013 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 onwords16 to 31 when run from from 1st until the 15thMore clearly:If today is 2013-10-07 then startdate is : 2013-09-16 enddate is : 2013-09-31if today is : 2013-10-23 then startdate is : 2013-10-01 enddate is: 2013-10-15The 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 More sharing options...
marianol Posted October 7, 2013 Share Posted October 7, 2013 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 DatesAnother 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 More sharing options...
sadakar Posted October 8, 2013 Author Share Posted October 8, 2013 Thank you Link to comment Share on other sites More sharing options...
sadakar Posted October 9, 2013 Author Share Posted October 9, 2013 Thank you marianolhttp://jasper-bi-suite.blogspot.in/2013/10/startdatefromdate-and-enddatetodate.html Link to comment Share on other sites More sharing options...
tj.tripp Posted December 30, 2019 Share Posted December 30, 2019 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now