soma Posted July 25, 2007 Share Posted July 25, 2007 Hi, I am a new user in iReport and have a requirement to add days to date value passed by the user. Then do a sql query based on the new date. Can someone tell me how can I do this? I am using iReport 1.3.3 and MySQL. RegardsSoma Link to comment Share on other sites More sharing options...
codyjasperForge Posted July 25, 2007 Share Posted July 25, 2007 What type of 'Date' are you using? -> java.util.Date-> java.sql.Date-> java.util.Calendar Research which ever you are using, there are methods that allow you to manipulate dates in each of these...Good luck. Link to comment Share on other sites More sharing options...
soma Posted July 25, 2007 Author Share Posted July 25, 2007 Hi , I am using java.util.Date. At what point I call the java methods? is it possible to give me a sample call format? RegardsSoma Link to comment Share on other sites More sharing options...
codyjasperForge Posted July 25, 2007 Share Posted July 25, 2007 First of all, most of the java.util.Date class's methods have been deprecated by java.util.Calendar methods. So my first suggestion is to use java.util.Calendar.-But thats just a suggestion. If I understand you correctly, you are receiving a 'Date' object from your parameter. Change this to java.util.Calendar. I would create a variable: Name = daysAddedClass = java.util.Calendar()Reset Type= NONECalculation Type = NONEIncrement Type = NONEInitial Expression = $P{Name of your incoming parameter}Variable Expression = $P{NameOfYourParam}.CalendarFunctionToSetDays() I don't know the exact function you need for the underlined above, but here is the link that you need. http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#method_summary Then create a Parameter, Call it newDate.Parameter expression should be $V{daysAdded}Use this parameter in your query... Let me know if this works... Link to comment Share on other sites More sharing options...
soma Posted July 27, 2007 Author Share Posted July 27, 2007 Hi, Thanks for the reply, I was able to add the date but when I move my $V{adddate} to pramenter $P{newDate}, I am getting null value inside newDate. I am using the Default Parameter Expression box to move the adddate to newDate. RegardsSoma Link to comment Share on other sites More sharing options...
bklawans Posted July 27, 2007 Share Posted July 27, 2007 If you only need to use the new date as part of a filter, consider doing it all in the query. If you have two parameters, one the date entered and one the number of days, you can use the MySQL DATE_ADD function where you need the new date. Your query would contain something like Code:WHERE some_field < DATE_ADD($P{date}, INTERVAL ${num_days} DAY) -BarryPost edited by: bklawans, at: 2007/07/27 00:06 Link to comment Share on other sites More sharing options...
codyjasperForge Posted July 27, 2007 Share Posted July 27, 2007 I was able to add the date but when I move my $V{adddate} to pramenter $P{newDate}, I am getting null value inside newDate This raises the question: Which value gets filled first, variable values or parameter values...? How is it that you know the 'null' value exists? Are you displaying it in a textfield?If so, try changing the evaluation time of your textfield, see if that will give you the value of $V{adddate} inside of $P{newDate}.. Does this work? Link to comment Share on other sites More sharing options...
gpecurto_1 Posted June 1, 2017 Share Posted June 1, 2017 subtracting one monthEDATE($P{yourDateParam}, -1) 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