jasper reports - taking "new java.util.Date()" and making it 1 month prior -


i'm using jaspersoft's ireport , want turn new java.util.date() (which current date) 1 month prior date. write in text field expression achieve this?

you can use joda-time java api. call minusmonths method on datetime object.

the jrxml file sample:

<?xml version="1.0" encoding="utf-8"?> <jasperreport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="joda_sample" pagewidth="595" pageheight="842" whennodatatype="allsectionsnodetail" columnwidth="555" leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20">     <import value="org.joda.time.datetime"/>     <title>         <band height="79" splittype="stretch">             <textfield>                 <reportelement x="109" y="23" width="175" height="20"/>                 <textelement/>                 <textfieldexpression><![cdata["current date: " + new simpledateformat("dd.mm.yyyy").format(new date())]]></textfieldexpression>             </textfield>             <textfield>                 <reportelement x="336" y="23" width="200" height="20"/>                 <textelement/>                 <textfieldexpression><![cdata["current date minus 1 month: " + datetime.now().minusmonths(1).tostring("dd.mm.yyyy")]]></textfieldexpression>             </textfield>         </band>     </title> </jasperreport> 

the result be:

the result in ireport

note: don't forget add joda-time library classpath (in case i've add library ireport's classpath).


Comments