How do I use parametes to calculate a date 10 years back?

0

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.  

bernie.obrigewitsch's picture
Joined: Nov 13 2013 - 12:19pm
Last seen: 5 years 4 months ago

3 Answers:

0

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.   

 

bernie.obrigewitsch's picture
Joined: Nov 13 2013 - 12:19pm
Last seen: 5 years 4 months ago
1

Hi give date java expression in default value expression. thanks Shailesh

comsym's picture
18
Joined: Jul 31 2012 - 4:06pm
Last seen: 1 year 2 weeks ago

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

bernie.obrigewitsch - 5 years 4 months ago
-1

try this in your expression 

DATEFORMAT(new java.util.Date( NOW( ).getTime() - (1000*60*60*24*365*10))    ,"YYYY-MM-DD")

haidar_hadi_205's picture
Joined: May 14 2014 - 12:47pm
Last seen: 5 years 3 months ago

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?

bernie.obrigewitsch - 5 years 4 months ago

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.

bernie.obrigewitsch - 5 years 4 months ago

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

haidar_hadi_205 - 5 years 4 months ago
show 2 more...

still did not work.. see below what i did to get it to work..

bernie.obrigewitsch - 5 years 4 months ago

this did not work this is what i did
new java.util.Date($P{BeginVisitDate}.getTime() - 3653L*24*60*60*1000)

bernie.obrigewitsch - 5 years 4 months ago
Feedback