mbritton Posted June 22, 2010 Share Posted June 22, 2010 Hi,I have a report in which the user enters two dates $P{StartDate} and $P{EndDate}, which are (strangely enough), the start and end date of the report. I'm looking for a way to return a blank report (or even better, an error message), if EndDate is more than 6 months after StartDate (we're having memory issues and need to stop people from pulling large lists of data, so that our app doesn't crash). Thanks in advance for the help! Link to comment Share on other sites More sharing options...
jroeterd Posted June 22, 2010 Share Posted June 22, 2010 calculate days between both prompt dates and use in filter to prevent uses for more then 180 days or something like that. Jeroen Link to comment Share on other sites More sharing options...
slow Posted June 23, 2010 Share Posted June 23, 2010 try this:define a variable, date_sub, of type Long as this:new Long((new SimpleDateFormat ("yyyy.MM.dd").parse ($P{EndDate}).getTime()- new SimpleDateFormat ("yyyy.MM.dd").parse ($P{StartDate}).getTime()) /86400000L )(use the date format you want but modify the string "yyyy.MM.dd"....)if the user give two dates wich subtraction is more than 180 days, then you can choose two way... the first is to represent only data between the start date and six months after date...the second is to represent nothingthe six-month-after-start-date can be obtained declaring a variable as after_6_month_date:Date object: (new SimpleDateFormat ("yyyy.MM.dd").parse ($P{StartDate}).getTime()+86400000L*180)if you want to represent nothing you can pass to the sql statement two dates that can't be subtracted... such as 2010.01.01 and 2009.31.12the date of a day before the start date can be obtained with a variable date_beforeDate object: (new SimpleDateFormat ("yyyy.MM.dd").parse ($P{StartDate}).getTime()-86400000L)so you can use a variable real_end_date setting it to:$V{date_sub}.longValue<180? $P{EndDate} : $V{after_6_month_date}if you want to show something...$V{date_sub}.longValue<180? $P{EndDate} : $V{date_before}if you want to show nothing...and then pass to the sql statement the $P{StartDate} and the $V{real_end_date} pay attention to pass only string-dates to the sql statement in the format your db exptect them...is use it... :)_________________________________________if it works... give me KARMA points please! : ) _________________________________________listening: Death in Vegas - Dirge Link to comment Share on other sites More sharing options...
mbritton Posted June 23, 2010 Author Share Posted June 23, 2010 Slow, thanks for the help. However, when I change the $P{EndDate} parameter in my sql query to $V{EndDate} (which is my name for your $V{real_end_date}, I get at sql error at '$'. Any idea what could cause this? Link to comment Share on other sites More sharing options...
mbritton Posted June 23, 2010 Author Share Posted June 23, 2010 Never mind, I fixed this by changing all the variables to parameters, using the same expressions you suggested. Thanks so much! Link to comment Share on other sites More sharing options...
kiwiyo Posted July 31, 2010 Share Posted July 31, 2010 Hi mbritton,When i tried to limit the date range, i get this error msg:1. The method parse(String, ParsePosition) in the type SimpleDateFormat is not applicable for the arguments (Date Need your advise on this :)Thanks :) 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