3 Replies Latest reply on Oct 29, 2007 11:47 AM by atta707

    date Manipulation

    trycold Level 1
      Hi,

      I need to display dates for 7 days after i choose a date in the calendar startting from the date which was selected. I have something like this:

      <mx:DateChooser id="dateChooser" disabledDays="[0,6]" change="displayDate(DateChooser(event.target).selectedDate)"
      disabledRanges="{[{rangeEnd:new Date(startDate.getTime()+ (2* millisecondsPerDay))}]}" />

      private function displayDate(date:Date):void {
      if (date == null)
      selection.text = "Date selected: ";
      else{
      selection.text = "Date selected: " + date.getFullYear().toString() +
      '/' + (date.getMonth()+1).toString() + '/' + date.getDate();
      var startDate:Date = new Date(date.fullYear,date.month,date.date,0,0,0,0);
      for(var x:Number = 0; x < 7; x++){
      var nowDate:Date = new Date(startDate.getTime() + x* millisecondsPerDay);
      var tDay:Number = nowDate.getDay();
      Alert.show(''+tDay);}}}

      The first time I run the program I get day 0 twice. Specially if I select Thursday or friday. I don't know why is it doing this?

      Thanks

        • 1. Re: date Manipulation
          atta707 Level 2
          getDay();
          Returns the day of the week (0 for Sunday, 1 for Monday, and so on) specified by this Date according to local time. Local time is determined by the operating system on which Flash Player is running.


          Returns Number — A numeric version of the day of the week (0 - 6) a Date object represents.

          ATTA
          • 2. Re: date Manipulation
            trycold Level 1
            Hi,

            Maybe my qs. was not clear. What I want to know is if I run the loop like this. I get Sunday twice. E.g if i select 1st Nov then for nowDate I have:

            Thu Nov 1 00:00:00 GMT-0400 2007
            Fri Nov 2 00:00:00 GMT-0400 2007
            Sat Nov 3 00:00:00 GMT-0400 2007
            Sun Nov 4 00:00:00 GMT-0400 2007
            Sun Nov 4 23:00:00 GMT-0500 2007
            Mon Nov 5 23:00:00 GMT-0500 2007
            Tue Nov 6 23:00:00 GMT-0500 2007

            Thanks


            • 3. Re: date Manipulation
              atta707 Level 2
              Okay, I see. So wouldn't setDate() would be simpler in this case?

              Sets the day of the month, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running

              I know I'm not answering your question directly now as I'm little intimidated by the code :)

              ATTA