Issue Description:
The following are a couple of examples on how to use relative dates in jrxml report.
Resolution:
You can define two parameters and two date type input controls with the following names, e.g. BeginDate and EndDate. The two input controls will be initialized with the respective parameter defaultvalueexpression.
<parameter class="net.sf.jasperreports.types.date.DateRange" name="BeginDate"> <defaultvalueexpression> <![CDATA[new net.sf.jasperreports.types.date.DateRangeBuilder("WEEK-14").toDateRange()]]> </defaultvalueexpression> </parameter> <parameter class="net.sf.jasperreports.types.date.DateRange" name="EndDate"> <defaultvalueexpression> <![CDATA[new net.sf.jasperreports.types.date.DateRangeBuilder("WEEK-1").toDateRange()]]> </defaultvalueexpression> </parameter>
You can use these parameters in the query in conjunction with $X, e.g.
$X{BETWEEN, column, BeginDate, EndDate}
Another Example, retrieve results prior to the end of last month
<parameter class="net.sf.jasperreports.types.date.DateRange" name="EndDate"> <defaultvalueexpression> <![CDATA[new net.sf.jasperreports.types.date.DateRangeBuilder("MONTH-1").toDateRange().getEnd()]]> </defaultvalueexpression> </parameter>
Query requires $X syntax since $P function does not support relative date classes.
select * from orders where $X{LESS, order_date, EndDate}
Ref. Case #00034561
Recommended Comments