xok Posted March 1, 2012 Share Posted March 1, 2012 Hello,How can I convert a String parameter to a Date?I want to type a date in the format "yyyy-MM-dd" as a string parameter and then convert it in the format "dd-MM-yyyy" just to be written in a text box. Note: I do not want a date parameter as it will shred the report because I have 9 datasources using the parameter as a String ;) Post Edited by robccsilva at 03/01/2012 14:28Post Edited by robccsilva at 03/01/2012 15:39 Link to comment Share on other sites More sharing options...
xok Posted March 1, 2012 Author Share Posted March 1, 2012 I am doing further tests and there are things that I dont understand...I have the following elements on a test report:1 - Variable: $V{vDATE} - java.lang.StringDefined as:new SimpleDateFormat("yyyy-MM-dd").parse("2011-11-13") 2 - An text box with Text Field Expression:$V{vDATE}Results in NULL 3 - An text box with Text Field Expression:new SimpleDateFormat("yyyy-MM-dd").parse("2011-11-13")Results in 13-11-2011 0:00 Why does does element #2 result in NULL ?I find this behaviour very weird ! Link to comment Share on other sites More sharing options...
xok Posted March 1, 2012 Author Share Posted March 1, 2012 After struggling several hours over this issue, I have found the problem.So that the variable works properly as expected, instead of using "Variable Expression" we must use "Initial Value Expression":new SimpleDateFormat("yyyy-MM-dd").parse("2011-11-13") Then we can use an text box and format the way we want. .e.g "dd-MM-yyyy". Can anyone explain why do I have to use "Initial Value Expression" instead of "Variable Expression"?This seems to me a bug... or am I using the varaibles in a wrong way. 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