dprogrammer Posted August 10, 2009 Share Posted August 10, 2009 Hi, Ihave a date parameter of format 'yyyy-mm-dd', I would like to subtract month from it. For example:If Date = '2009-08-01', then I would like to pass it as '2009-06-01'. I don't see any function in iRepor 1.2, any ideas please? Link to comment Share on other sites More sharing options...
jbl429 Posted August 11, 2009 Share Posted August 11, 2009 Yes, I'm trying to do the same thing. Any help would be greatly appreciated. Thanks!Post Edited by jbl429 at 08/11/2009 13:54 Link to comment Share on other sites More sharing options...
jbl429 Posted August 19, 2009 Share Posted August 19, 2009 can anyone help? Link to comment Share on other sites More sharing options...
belmus Posted August 20, 2009 Share Posted August 20, 2009 try it in SQL order or use java.util.Calendar class Link to comment Share on other sites More sharing options...
m_anands Posted August 20, 2009 Share Posted August 20, 2009 you can use jado to do that.You need to put this jar in lib of ireport and thn you can use jado API to substract. Link to comment Share on other sites More sharing options...
mdahlman Posted September 3, 2009 Share Posted September 3, 2009 This is indeed a common requirement. As belmus alludes to, you can generally perform this calculation in the SQL query. The syntax can be ugly, and of course that doesn't work if you aren't using SQL. I like to do this calculation in the SQL query most times. But when that's not possible... The best solution that I know of to do this calculation inside the report itself is to use Apache Commons Lang. Get the .jar file. Put in in the classpath (using Tools -> Options -> Classpath). Then use code like this: org.apache.commons.lang.time.DateUtils.addMonths($P{MyDate},-1) Nice, eh? (The big qualified classname makes it look worse than it is.) Regards,Matt Link to comment Share on other sites More sharing options...
C-Box Posted September 4, 2009 Share Posted September 4, 2009 if you put "org.apache.commons.lang.time.*" into the report imports the expression would just be: DateUtils.addMonths($P{MyDate},-1) just to shorten the expression! (so we do with our own DateLib) just my two cents C-Box Link to comment Share on other sites More sharing options...
mdahlman Posted September 9, 2009 Share Posted September 9, 2009 CBox, Yes, I was too lazy to mention the importing of the package. But that makes for much more readable code. I finally got around to posting a sample report that does some date calculations. (And I followed your suggestion of using the import!) For anyone interested, my post includes a discussion of date functions in JR and a sample report with some useful date calculations like "MyDate - 3 days" and "the first day of the month". Regards,Matt 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