Jump to content
We've recently updated our Privacy Statement, available here ×

Setting default date parameters for weekly reports


tugrul083
Go to solution Solved by H Mendoza,

Recommended Posts

Hi,

I have been stuck with this for a long time now and would really appreciate any help to get me going.

I want to add default values for my startdate and enddate parameters such that they are set to "Last Sunday" and "Sunday before" by default. This will enable me to schedule weekly reports while still giving the users to change the report dates on their convenience.

I am not proficient with Java and the fact that Jasper Studio allows only 1 expression in a paramater doesn't help.

I have tried using the following expressions. They did work for a couple of reports but didn't give the correct dates for others. Also with reports that use stored procedures, it simply won't work. There's something wrong and it's unreliable.

Startdate: new SimpleDateFormat("yyyy-MM-dd").format(NOW()-(WEEKDAY(NOW())+7))

Enddate: new SimpleDateFormat("yyyy-MM-dd").format(NOW()-(WEEKDAY(NOW())))

The sql equivalent of what I'm trying to write would be the following.

Startdate: DATE_SUB(DATE(NOW()), INTERVAL DAYOFWEEK(NOW())+6 DAY)

Enddate: DATE_SUB(DATE(NOW()), INTERVAL DAYOFWEEK(NOW())-1 DAY)

Any help would be greatly appreciated. Many thanks and regards.

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution
  • 2 weeks later...

Thank you so much Hugo! Using date range parameters I've solved the issue with most of my reports! :-)

I'd like to ask another question if I may; Date range parameters worked fine for both SQL queries run on the report AND on a stored procedure which has only date inputs. ie. CALL Stored_Procedure $X(startdate, enddate). This works fine.

However the "$X()" syntax doesn't seem to work with stored procedures that have more than 2 paramater inputs such as CALL Stored_Procedure $X(startdate, enddate, ID1, ID2. ID3, ID4, ID5, ID6) 

Any ideas? 

Many thanks and regards,

Tugrul

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