6

I have to convert one string type field to date datatype in flex.

What can I do solve this problem?

Jason Towne
  • 8,014
  • 5
  • 54
  • 69
Nidhi
  • 755
  • 3
  • 11
  • 25
  • Have you had a chance to try the answer I posted? If it helps solve your problem, you can upvote it by clicking on the ^ arrow and flag it as the accepted answer by clicking on the check mark icon next to my answer. – Jason Towne Jun 01 '11 at 20:07

3 Answers3

6
import mx.controls.DateField;

var dateString:String = " 25/02/2009";
var date:Date= DateField.stringToDate(dateString,"DD/MM/YYYY");

with credit to: http://amthekkel.blogspot.com/2009/02/flex-converting-date-string-to-date.html

asok Buzz
  • 1,876
  • 3
  • 24
  • 50
invertedSpear
  • 10,864
  • 5
  • 39
  • 77
4
var str:String = "25/02/2009"
var d:Date = new Date(str);

or

we can use a custom DateUtils class

package 
{
  import mx.formatters.DateFormatter;

  public class DateUtils extends DateFormatter
 {
    public function DateUtils()
   {
     super();
   }



  public static function parseString (str:String):Date {
      return parseDateString(str);
  }

 }
}
Jason Towne
  • 8,014
  • 5
  • 54
  • 69
girija
  • 41
  • 4
0

You can also use the Date.parse function with the Date.setTime function to create a new Date object from a string.

var myDateString:String = "05/10/2011";
var myDate:Date = new Date();

myDate.setTime(Date.parse(myDateString));
Jason Towne
  • 8,014
  • 5
  • 54
  • 69