HBK32 Posted August 6, 2007 Share Posted August 6, 2007 Hi, 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,Badrish.:) Link to comment Share on other sites More sharing options...
redwine Posted August 7, 2007 Share Posted August 7, 2007 Badrish 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}. hth! edwin Link to comment Share on other sites More sharing options...
HBK32 Posted August 7, 2007 Author Share Posted August 7, 2007 Hi, 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 More sharing options...
takashi Posted August 7, 2007 Share Posted August 7, 2007 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 Takashi Link to comment Share on other sites More sharing options...
HBK32 Posted August 8, 2007 Author Share Posted August 8, 2007 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 Badrish.:) Link to comment Share on other sites More sharing options...
vk01 Posted February 9, 2008 Share Posted February 9, 2008 I tried this syntax and it is not working :( This field is a string, and not a java.util.date Is there any way i can convert a string to required date format? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now