Jump to content
Changes to the Jaspersoft community edition download ×

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


Go to solution Solved by bernie.obrigewitsch,

Recommended Posts

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

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

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

  • Solution

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

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...