3 Replies Latest reply on Jan 24, 2007 4:13 PM by QuickStick

    date

    GeorgeWS Level 1
      I have been reading for days about dates and can not find a sample that is just showing the date in a mx:text I tried making a function but I always get a null. Can anyone show me a sample that has just the current date?

      Thanks
      George
        • 1. Re: date
          QuickStick Level 1
          George,

          This code will write out a full date (Tuesday, 23 January 2007), hope it helps:

          //Create a new Date object...
          public var dateTime:Date = new Date();

          //Function to retrieve a date...
          public function getDate() {

          //Array of days and months...
          var dateDay:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
          var dateMonth:Array = new Array("January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

          //Create the string of day, date, month and year...
          var dateFull:String = new String(dateDay[dateTime.day] + ", " + dateTime.date + " " + dateMonth[dateTime.month] + " " + dateTime.fullYear);

          }

          Do what you will with the dateFull variable after this.

          Cheers
          Oz
          • 2. Re: date
            GeorgeWS Level 1
            I see whats going on but it does not really work. I had to add the : void after the function getDate. Then there are warning errors. and when I do try and show the dateFull its blank. BUT... if I just put {dateTime} it shows the day the date the time the year. So that part works. Also if I put {dateTime.fullYear} it shows 2007 so thats cool. but when I put {dateTime.month} its blank, the others seem to work fine {dateTime.day} and {dateTime.date}. Why doesnt the month work?

            George
            • 3. Re: date
              QuickStick Level 1
              Sorry George, I took that function from a previous project, and forget to put the "void" in.

              The definition of 'month' is:

              month : Number
              The month (0 for January, 1 for February, and so on) portion of a Date object according to local time.

              Hopefully that helps you.

              Change the 'void' to 'string' and add 'return dateFull' to the end, and try calling the function with something like 'dateNow = getDate();', and then put dateNow into a label, you may have some more luck.