PDA

View Full Version : Date don't work with 'YYYY-MM-DD' format


hardcoremore
09-11-2009, 08:40 PM
Hi, how come that when i write


trace(new Date('2009/04/22').toString())


it works fine, however when i write


trace(new Date('2009-04-22').toString())


its says Invalid Date


This is really stupid or i am missing somethin cauz there is no attribute in date constructor that i can pass as separator.

This cause me big problems for dateField as itemEditor in data grid becauze
mysql returns me date in YYYY-MM-DD format and when i try to edit the row
it says type coercion failed Cannot convert "2009-02-05" do date

I really don't understand what is it here all about.

hardcoremore
09-11-2009, 09:10 PM
And i have data grid with date column like this:


<mx:DataGridColumn dataField="vremeZavrsetkaNagrade"
headerText="Zavrsetak Nagrade" editorDataField="selectedDate"
editable="true">
<mx:itemEditor>
<mx:Component>
<mx:DateField formatString="YYYY-MM-DD" editable="false" />
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>


when i try to edit it it sasy Type Coercion failed: cannot convert "2009-09-06" to Date.

Mysql returns me date in YYYY-MM-DD format. I mean what i am doing. I put mysql fields as text type and insert date in YYYY/MM/DD but again gives me error this time Type Coercion failed: cannot convert "2009/09/06" to Date.

I fond one examle on internet for use of DateField as data grid itemEditor but in his example he uses this array collection for data provider:


public var ac:ArrayCollection = new ArrayCollection(
[{dateString:"11/12/2006", contact:"ABD DEF", dt: new Date(2003,10,23)},
{dateString:"11/12/2007", contact:"GHI", dt:new Date(2004,11,2)},
{dateString:"10/10/2007", contact:"JKL MNOP", dt:new Date(2007,4,14)},
{dateString:"09/12/2007", contact:"QRSTUV W XY Z", dt:new Date(2006,1,1)}]);



but my array collection is taken from server and i really don't know what to do

Peter Cowling
09-12-2009, 09:46 PM
public var ac:ArrayCollection = new ArrayCollection( [{dateString:"11/12/2006", contact:"ABD DEF", dt: new Date(2003,10,23)}, {dateString:"11/12/2007", contact:"GHI", dt:new Date(2004,11,2)}, {dateString:"10/10/2007", contact:"JKL MNOP", dt:new Date(2007,4,14)}, {dateString:"09/12/2007", contact:"QRSTUV W XY Z", dt:new Date(2006,1,1)}]);


In that example, the expected format is used to create a new date: new Date followed by three comma separated arguements. You need to feed the data in this format.