Jump to content
We've recently updated our Privacy Statement, available here ×

Date format


yyhor

Recommended Posts

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

The following is the jrxml code of the date field. Although i have converted it to String, but it still display the format "yyyymmdd" (this is the format which is stored in db).

<textField isStretchWithOverflow="false" pattern="dd-MMM-yyyy" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
     <reportElement
      x="436"
      y="103"
      width="75"
      height="12"
      key="textField"/>
     <box></box>
     <textElement>
      <font fontName="Courier New" pdfFontName="Courier" isPdfEmbedded ="false"/>
     </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA[$F{BILL_DT}]]></textFieldExpression>
    </textField>

Thanks & Regards,

yy

Link to comment
Share on other sites

In this case all you have done is put an Integer value in a field defined as a String. What you should try is using the Java method to convert your value to a String then use a date formatter

new SimpleDateFormat('dd-MMM-yyyy").parse( $F{BILL_DT } .toString());

Set the class to  java.util.Date.

 

 

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

Many thanks for your reply.

I have tried to create a variable and class type as java.util.Date, which is :

<variable name="BILL-DT" class="java.util.Date" resetType="Report" calculation="Nothing">
  <variableExpression><![CDATA[new SimpleDateFormat("dd MMM yyyy").parse($F{BILL_DT})]]></variableExpression>
 </variable>

 

but i'm having the errors as below:-

Error filling print... Error evaluating expression :
      Source text : new SimpleDateFormat("dd MMM yyyy").parse($F{BILL_DT})
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :
      Source text : new SimpleDateFormat("dd MMM yyyy").parse($F{BILL_DT})
      at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:257)
      at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:528)
      at net.sf.jasperreports.engine.fill.JRCalculator.estimateVariables(JRCalculator.java:173)
      at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:753)
      at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1422)
      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:111)
      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:879)
      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:782)
      at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)
      at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)
      at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234)
      at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:947)
      at java.lang.Thread.run(Unknown Source)
Caused by: java.text.ParseException: Unparseable date: "20080114"
        at java.text.DateFormat.parse(Unknown Source)
        at R1_1224056800132_539306.evaluateEstimated(R1_1224056800132_539306:812)
        at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:246)
        ... 12 more 
Print was not filled. Try using an EmptyDataSource...
 

any ideas ?

 

Thanks & Regards,

yy

Link to comment
Share on other sites

The standard Java date parser doesn't recognize the yyyymmdd format.

You can try something like

<CODE>new java.util.Date(-1900+d/10000, -1+(d%10000)/100 ,d%100); </CODE>

That's a deprecated constructor but you can check the Java docs for a replacement.

No offense, but I would suggest database redesign. Having the date stored as an integer in this format means you can't do date arithmetic (i.e., subtract two dates).

Link to comment
Share on other sites

  • 3 years later...

Hi to all!I try to implement table subreport. When I generate the table I get org.apache.commons.beanutils.ConversionException: Unparseable date: "1997/08/25"My pattern is "yyyy, MMM dd" and the class of the field is java.util.Date. This is the xmldatasource semple in jasper report package.What I missing?Please Help...Mennei.

 

Post Edited by mennei at 10/26/2011 09:43

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...