Jump to content
Changes to the Jaspersoft community edition download ×

Setting default expression for startdate / enddate: The Sunday before, Last Sunday etc..


tugrul083

Recommended Posts

 

Hi All,

I'd like to set a default value expression for the stardate and enddate parameters of my report. The idea is that the date prompt screen would always open with values;

Startdate: Sunday before

Enddate: Last sunday

But the user can also change the values if they want. Basically what I need to write is a Java or Groovy conversion of the following SQL expressions:

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

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

Jaspersoft Studio doesn't allow usage of calendar functions and I'm badly stuck. Any help would be greatly appreciated!

 

Thank you!

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

I'm kind of getting there...  I've created 3 parameters:

1. P{cal}, java.util.calendar, default value expression: Calendar.getInstance()

2. P{startdate}, java.util.date, default value expression:

($P{cal}.add(Calendar.DAY_OF_WEEK,-($P{cal}.get(Calendar.DAY_OF_WEEK)-1)))

? null :  $P{cal}.getTime()

3. P{enddate}, java.util.date, default value expression: 

($P{cal}.add(Calendar.DAY_OF_WEEK,-($P{cal}.get(Calendar.DAY_OF_WEEK)+6)))

null :  $P{cal}.getTime()

These find the sunday before, and the sunday before that. What I need is "Last Sunday" and "Sunday before". So basically these parameters are following a week behind... Any comments???

Link to comment
Share on other sites

  • 2 weeks later...

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