Jump to content

[SOLVED] (BUG ?) How to convert a String parameter to a Date?


xok

Recommended Posts

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:28



Post Edited by robccsilva at 03/01/2012 15:39
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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

Defined 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

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

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