Jump to content

How to set default date as yesterday's date


xiudeng

Recommended Posts

I am trying to set default date as yesterday's date for a Date parameter, which is a java.util.Date type.  I put the following expression in the "Default Value Expression" section:

new Date((new Date()).getTime()-24*60*60*1000)

But I still got today"s date as default value.  Any ideas?

Thanks,

Sue

 

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Yes, it is an input control that pops up to run the report.  I created a parameter called from_date and I want it shows yesterday's date when the input control pops up.  Of course I can change it to any date if I want. 

Here is what I did:  I right click on the from_date parameter and then select "Edit",  so the "Add/modify parameter" dialog box appears.  Than I choose  "java.util.Date" for  "Parameter Class Type" and  put "new Date(new Date().getTime()-1000*60*60*24)" in "Default Value Expression" section.

I found that no matter what I put in the "Default Value Expression" section, even left it blank, the default pop up value is always today's date.

Link to comment
Share on other sites

  • 10 months later...

 ok i am having the same problem.. no matter what expression i put, i still get today's current date.

 

i have tried 

new Date((new Date()).getTime()-24*60*60*1000)

Calendar.getInstance().add(Calendar.DATE, -1).getTime()

 

none of these works. =( please advise

Link to comment
Share on other sites

 ok just figured things out

this expression works:

 

new Date((new Date()).getTime()-24*60*60*1000)

 

did work for me at first coz i set the default value for my date prompt $P{reportDate} to 'new Date()', and whenever i blank the prompt, the current date is used instead of the expression i used in $V{reportDate} that is supposed to generate the yesterday's date

 

the following expression doesn't work coz the function Calendar.add() returns void

 

Calendar.getInstance().add(Calendar.DATE, -1).getTime()

 

 

Link to comment
Share on other sites

  • 3 years later...
  • 8 months later...
  • 3 years later...
  • 5 months later...
  • 5 years later...
On 1/10/2019 at 8:13 AM, tony.dunlop said:

You can use:

EDATE(TODAY(), -1)[/code]

In the parameter default field

 

I tried this with both java.util.Date and java.sql.Date and they each return today's date, but last month.  
Ex: today is Sept 26th (as provided by the TODAY() function), but EDATE(TODAY(),-1) returns Aug 26.  I was expecting Sep 25, of course.
I like the elegance, but can't figure out why it's not working, @tony.dunlop.
_______
@shishir1601 This returns today, regardless of the class or if I used minus 2.
new Date(System.currentTimeMillis()- 1)
-----------

This seems over-engineered, but works, so I'm using it. Thanks @martin.ensp!

DATE(        YEAR(DATEVALUE(TODAY( ) )-24*60*60*1000),       MONTH(DATEVALUE(TODAY( ) )-24*60*60*1000),       DAY(DATEVALUE(TODAY( ) )-24*60*60*1000) )
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...