bernie.obrigewitsch Posted June 2, 2014 Share Posted June 2, 2014 I have a begin and end date parameter.. I need to calculate a end date that would be 10 years ago.. I am using Ireports. Link to comment Share on other sites More sharing options...
comsym Posted June 2, 2014 Share Posted June 2, 2014 Hi give date java expression in default value expression. thanks Shailesh Link to comment Share on other sites More sharing options...
bernie.obrigewitsch Posted June 2, 2014 Author Share Posted June 2, 2014 I have tried doing that and it does not work.. I created a variable and tried to subtract 10 years from the parameter date (the user keys in), to get a new date. I got errors on the code. So, I am unsure of how to code it to get it to work. I know about the default value expressions but unable to get it working.. in my research most people say to do it in sql to make it easier Link to comment Share on other sites More sharing options...
haidar_hadi_205 Posted June 4, 2014 Share Posted June 4, 2014 try this in your expression DATEFORMAT(new java.util.Date( NOW( ).getTime() - (1000*60*60*24*365*10)) ,"YYYY-MM-DD") Link to comment Share on other sites More sharing options...
bernie.obrigewitsch Posted June 4, 2014 Author Share Posted June 4, 2014 I tried something like that, got errors. But what i need it $PBeginDate in it. So would DateFormat(new java.util.Data($PBeginDate.getTime() - (1000*60*60*24*365*10)), "MM-dd-yyy" work? Link to comment Share on other sites More sharing options...
bernie.obrigewitsch Posted June 4, 2014 Author Share Posted June 4, 2014 I added this DATEFORMAT(new java.util.Date($P{EndVisitDate}.getTime() - (1000*60*60*24*365*10)) ,"MM-dd-yyyy") and it does not error out now.. but my paramater date = 12/31/2013, result = 12-09-2013. so not subtracting from the year. I would need it to be 12/31/2003 as the result. Link to comment Share on other sites More sharing options...
haidar_hadi_205 Posted June 4, 2014 Share Posted June 4, 2014 here is the expression you need, just replace "12/01/2013" with your parameter new java.util.Date(new SimpleDateFormat("MM/dd/yyyy").parse("12/01/2013").getTime() -315569259747L) if you need to further format the output then use DATEFORMAT(new java.util.Date(new SimpleDateFormat("MM/dd/yyyy").parse("12/01/2013").getTime() -315569259747L), "MM/dd/yyyy") Link to comment Share on other sites More sharing options...
Solution bernie.obrigewitsch Posted June 9, 2014 Author Solution Share Posted June 9, 2014 I figured this out... I created a parameter call ed 10yrdate, changed it to not use as a prompt. Than I used this code in the default expression.new java.util.Date($P{BeginVisitDate}.getTime() - 3653L*24*60*60*1000) the 3563 is the amount of days to subtract.. I started with 366 x 10, and had to adjust it until I got the right date. Link to comment Share on other sites More sharing options...
bernie.obrigewitsch Posted June 9, 2014 Author Share Posted June 9, 2014 still did not work.. see below what i did to get it to work.. Link to comment Share on other sites More sharing options...
bernie.obrigewitsch Posted June 9, 2014 Author Share Posted June 9, 2014 this did not work this is what i did new java.util.Date($P{BeginVisitDate}.getTime() - 3653L*24*60*60*1000) 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