tags:

views:

53

answers:

3

SCinitiationtarget.selectedDate = new Date(rows1[i]['InitiationTarget']);

I am setting my seletedDate in my DateChooser like this. The format i am getting from the Database is 2009-12-30.

Its displaying in correctly.

A: 

The first argument of Date constructor is called yearOrTimeValue and as its documentation says it accepts either year or time in UTC milliseconds. For proper Date construction use:

new Date(2009, 12, 30)
hleinone
This isn't completely accurate. From the docs: If you pass one argument of data type String, and the string contains a valid date, the Date object contains a time value based on that date.
quoo
You're right. I just read the documentation of the first argument, which doesn't bring up that use case. Crappy documentation I should say. Anyway it seems that dash is not allowed as a delimiter.
hleinone
+3  A: 

I believe the date object doesn't recognize the dash as a valid separator. You'll have to some how reformat your date objects.

For example this works:

var date:Date = new Date("2009/12/30");
myDateChooser.selectedDate = date;

But this doesn't:

var date:Date = new Date("2009-12-30");
myDateChooser.selectedDate = date;

For more information on what date formats are valid, see the documentation here: http://livedocs.adobe.com/flex/3/langref/Date.html#Date%28%29

quoo
That is what i am looking on how to reformat the date into YYYY/MM/DD as i am getting from the database as YYYY-MM-DD
oldDate.split('-').join('/'); or oldDate.replace(/-/, '/'); (although you'll want to double check my regex pattern in the replace method)
quoo
Did u check my solution
I suppose that works too, although it's a little odd to post it as a 'solution' to your own question, when it builds upon the other two answers to your question.
quoo
A: 

I got the solution finally.

var dateStr:String = dateFormatter.format(rows1[i]['InitiationTarget']);
SCinitiationtarget.selectedDate = new Date(dateStr);

<mx:DateFormatter id="dateFormatter" formatString="MMM D, YYYY"/>

With this the problem gets solved.