Jump to content
Changes to the Jaspersoft community edition download ×

String to Date


Recommended Posts



I am passing date parameter as a type string in format i.e. "YYYY-MM-DD", now I want to display in format "MM/dd/yyyy" format. Problem is I am passing date field as String type parameter.


How can I convert it to into perticular format("MM/dd/yyyy") in iReports/Jasper internally as I will get date field as a String type!!!


Reply as soon as possible.


Thanks in advance,


Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic



Your Date field must be a Text Field (not Static Text) for this to work.

In case you have a static field, just do this:

Right click on the date field and select Transform in Text Field (F3).

This will convert your static text element into a text field element.


Now, right click your date text field.

Select properties and click on the Text Field tab.

In the Text Field Expression Class select java.util.Date.

I am assuming that you are passing a date parameter as you have mentioned.

In the Evaluation Time, select Now.

In the Pattern type in "MM/dd/yyyy" or whatever pattern you need.

Lastly, in the text field expression indicate the parameter that you are using like $P{importantDate}.





Link to comment
Share on other sites



Yes I am using TextField only.....I did the same thing as you mentioned but it is giving this following error....as parameter type is String


net.sf.jasperreports.engine.JRException:ÂErrorsÂwereÂencounteredÂwhenÂcompilingÂreportÂexpressionsÂclassÂfile: 1. Cannot cast from String to Date value = (java.util.Date)(((java.lang.String)parameter_StartDt.getValue()));

Link to comment
Share on other sites

If your input String format is "YYYY-MM-DD", Let's assume $P{date} has the date in String.



(new GregorianCalendar(Integer.parseInt($P{date}.substring(0,4)),Integer.parseInt($P{date}.substring(5,7))-1,Integer.parseInt($P{date}.substring(8,10)))).getTime()


This will convert your String to java.util.Date Object. Then, you can specify Pattern such as dd/MM/yyy



Link to comment
Share on other sites

Thanks a lot for your kind reply.....

Yes it works......I found following way which also works.


(new SimpleDateFormat("yyyy-MM-dd")).parse($P{StartDt})


Then in pattern Tab you can define what ever date format you want.....like e.g. MM/dd/yyyy



Link to comment
Share on other sites

  • 6 months later...

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