xiudeng Posted March 26, 2009 Share Posted March 26, 2009 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 More sharing options...
Giulio Toffoli Posted March 27, 2009 Share Posted March 27, 2009 wich default value are you talking about?If you refer to the input control that pops up to run the report, it does not read the default from the jrxml.You're expression seems fine. Link to comment Share on other sites More sharing options...
xiudeng Posted March 27, 2009 Author Share Posted March 27, 2009 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 More sharing options...
nao921 Posted February 27, 2010 Share Posted February 27, 2010 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 More sharing options...
nao921 Posted March 1, 2010 Share Posted March 1, 2010 ok just figured things outthis 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 More sharing options...
s.jyothsna1 Posted December 21, 2013 Share Posted December 21, 2013 This will work for sure. new Date((new Date()).getTime()-24*60*60*1000).But If you want to subtract more days from current date then you should mention L(long) at last as given below. new Date((new Date()).getTime()-30*24*60*60*1000L).(gives past 30days date) Thanq nao921 Link to comment Share on other sites More sharing options...
shishir1601 Posted August 31, 2014 Share Posted August 31, 2014 new Date(System.currentTimeMillis()- 1) Link to comment Share on other sites More sharing options...
martin.ensp Posted August 2, 2018 Share Posted August 2, 2018 You can use this expression in the input control:DATE( YEAR(DATEVALUE(TODAY( ) )-24*60*60*1000), MONTH(DATEVALUE(TODAY( ) )-24*60*60*1000), DAY(DATEVALUE(TODAY( ) )-24*60*60*1000) )[/code] Link to comment Share on other sites More sharing options...
tony.dunlop Posted January 10, 2019 Share Posted January 10, 2019 You can use:EDATE(TODAY(), -1)[/code]In the parameter default field Link to comment Share on other sites More sharing options...
modell Posted September 26 Share Posted September 26 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 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