1 Reply Latest reply on Oct 27, 2006 9:08 AM by dimival

    Using date as a string comes out as Null

      I need to use dates in my appication that has to be in a specified format (DD/MM/YYYY). I believe I have set up the code correctly but whenever I call on my variables that contain the date string, I always get Null. Below is the code I'm using:

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="dateFormatter();">
      import mx.controls.Text;
      import mx.formatters.DateFormatter;

      public static const millisecondsPerDay:int = 1000 * 60 * 60 * 24;

      private var _yesterday:String;
      private var _begin:String;

      public var text:String = new String(_yesterday + _begin);

      public function dateFormatter():void {
      var df:DateFormatter = new DateFormatter();
      df.formatString = "DD/MM/YYYY";

      var currentDate:Date = new Date();
      var yesterdayDate:Date = new Date(currentDate.getTime() - (millisecondsPerDay));
      var beginDate:Date = new Date(yesterdayDate.getTime() - (millisecondsPerDay * 7));

      _yesterday = df.format(yesterdayDate);
      _begin = df.format(beginDate);



      <mx:Canvas id="canvas" creationComplete="dateFormatter()"
      horizontalScrollPolicy="off" color="white"
      width="400" height="60">
      <mx:Text id="theText" y="0" fontSize="12" text="{text}"/>

      Any help is appreciated.