Jump to content
  • How to use relative dates in jrxml static reports?


    Jim W
    • Features: Reports Version: v4.7 Product: JasperReports® Library

    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


    User Feedback

    Recommended Comments

    jbarger.consultant

    Posted

    I'd like to be able to put into the web report (Month-1) for a scheduled report. When running this in the Studio editor this works fine but when published to the server, it errors stating "Specify a valid value for type Date". This feature appears to be broken.

     

     



    Guest
    This is now closed for further comments

×
×
  • Create New...