john.v.little Posted August 28, 2014 Posted August 28, 2014 There seems to be a huge missing feature in jasper studio. It seems its not possible for a mortal to get yesterdays date, or do date arithmentic in general. We need a report which shows summaries for today, yesterday, last month, today last month, last quarter etc.I have read many forum posts postulating ways to get yesterdays date, and things like last month. It seems it is not feasible.This was suggested: DATE(YEAR(TODAY( )),MONTH(TODAY( )),DAY(TODAY( ))-1)But this is wrong - if it is the 1st today, then yesterday needs to be the last day of the previous month, not just day -1 of the current month.Other suggestions include writing java classes (you may as well say build a rocket to land a girbil on the moon), or using groovy. We tried using grovy, but the expression editor doesnt recognis groovy syntax.Is there no solution for this for normal report writers?We could duplicate the report 10 times, and hard code the requred date ranges in SQL, but this is a maintenance nightmare as we change the columns requently, and there are a lot of them. If we are goijng to do this, there is no point in us using Jasper - we may as well stick to manually producing reports.
Solution marianol Posted August 28, 2014 Solution Posted August 28, 2014 The attached report (date-calculations.jrxml) uses expression and variables to do those calculations, at least it will give you a start. I'll look in the built in date functions (DAY(), etc.), I had a sample but I cannot find it now.
john.v.little Posted August 29, 2014 Author Posted August 29, 2014 I tried using your examples, but when I put the same parameters into my project, I get this error: "The operator || is undefined for the argument type(s) of void, void" Any ideas?
john.v.little Posted August 29, 2014 Author Posted August 29, 2014 Also, yesterday variable express gives "The operator - is undefined for the argument types(s) Date, int. I have no idea how you got this to work - my version of jasper studio (5.6) has none of the date options that your code seems to have
ronnie.macleod Posted October 3, 2017 Posted October 3, 2017 This example worked for me straight out of the box as a stand alone report but I think Saravana's comment highlights John's problem because I suspect his report is written in Java and this report is written in Groovy.... I tried changing the language to Java and it gave the same errors John was seeing. I doubt he has the option of rewriting every report in groovy (I certainly don't) so I guess we are both still looking a for a simple solution to this problem. Otherwise its a great little resource to have tucked away...
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