Jump to content
Changes to the Jaspersoft community edition download ×

Displaying date from database in report


Recommended Posts

By: Kuldip Shah - kuldipshah

Displaying date from database in report

2006-02-22 07:22

I want to display date from database in different format. I am trying following but does not work. It's not displaying any date and no exception is raised. Please help.

 

Data field is:

<field name="gameday" class="java.util.Date">

</field>

 

...

Variable is:

<variable name="v_gameday_display" class="java.lang.String" resetType="Group" resetGroup="game_num">

<variableExpression><![CDATA[(new SimpleDateFormat("MMMMM dd, yyyy")).format($F{gameday})]]></variableExpression>

</variable>

 

...

textField is:

<textFieldExpression class="java.lang.String"><![CDATA[$V{v_gameday_display}]]></textFieldExpression>

</textField>

 

I don't know what went wrong there...

Thank you.

 

 

 

 

By: macoute3 - macoute3

RE: Displaying date from database in report

2006-02-22 07:36

I've tried:

 

<variable name="v_gameday_display" class="java.lang.String" resetType="Report" calculation="Nothing">

<variableExpression><![CDATA[(new SimpleDateFormat("MMMMM dd, yyyy")).format(new Date())]]></variableExpression>

</variable>

 

<textFieldExpression class="java.lang.String"><![CDATA[$V{v_gameday_display}]]></textFieldExpression>

</textField>

 

ant it works

 

 

 

 

By: Kuldip Shah - kuldipshah

RE: Displaying date from database in report

2006-02-22 07:42

I think you tried it with current system date. I want formatting date (for e.g. order purchase date) coming from database. Date is coming from db is in format "yyyy-MM-dd".

 

 

 

 

 

By: Aegis Thorne - aegisthorne

RE: Displaying date from database in report

2006-02-22 09:49

Is the data coming from the database as a String ? You should use SimpleDateFormat.parse(String) instead of SimpleDateFormat.format(Object); the second just accepts a Date or a Number.

 

If that isn't it can you give the text of the exception ?

 

 

 

 

By: Kuldip Shah - kuldipshah

RE: Displaying date from database in report

2006-02-22 12:12

Guys,

 

Thank you all for helping me. Actually I fixed the problem by myself. It's strange but true that if you create Varable to format date and then put variable in textfield, it does not work all times.

 

Now I am getting data field directly as java.util.Date and formating textfield directly using simpleDateFormat.

 

Please let me know if anyone needs actual XML code...

Link to comment
Share on other sites

  • 2 years later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

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...