6 Replies Latest reply on Sep 4, 2008 5:37 AM by amthekkel

    Problem with datefield

    amthekkel
      HI, i have a datefield which is part of a form. WHen the user clicks a button the datefield and a timeinput control are passed to a function where the time part of the date is set to the value in the timeinput control.
      My problem is when i am doing datefield.selectedDate and passing it as a parameter to the function, the function is receiving it as today's date rather than the selected Date. ie i am getting 3rd of september rather than say 9th of september.

      Any suggestions?

      many thanks,

      cheers,
      abhi
        • 1. Re: Problem with datefield
          Ventis85
          Can you post the code?
          • 2. Re: Problem with datefield
            amthekkel Level 1
            Hi Ventis,

            here is the code where i am declaring the datefield and the timeinput control(the time input control is part of the yahoo astra library)
            <mx:HBox width="100%">
            <mx:FormItem label="Start Time">
            <mx:DateField id="startDate" formatString="DD/MM/YYYY" showToday="true"/>
            </mx:FormItem>
            <mx:FormItem>
            <ns1:TimeInput id="startTime" displayTwoDigitHoursValue="true" showSeconds="false" showAMPM="false" useTwelveHourFormat="false"/>
            </mx:FormItem>
            </mx:HBox>

            here is the code for the submit button
            <mx:FormItem>
            <mx:Button label="Submit" width="160" height="30" dataChange="" click="getDateTime(startDate.selectedDate,startTime.value)"/>
            </mx:FormItem>


            here is my getDateTime function
            public function getDateTime(d:Date,d1:Date):Date
            { //here d represents the date and d1 the time component, the time component is working fine
            var d3:Date=d;
            var n:Number=d1.getTime();
            d3.setTime(n);
            Alert.show("new date is "+d3.toString()+d.toString());
            return d3;
            }
            • 3. Re: Problem with datefield
              Level 7

              "amthekkel" <webforumsuser@macromedia.com> wrote in message
              news:g9lrlm$rup$1@forums.macromedia.com...
              > Hi Ventis,
              >
              > here is the code where i am declaring the datefield and the timeinput
              > control(the time input control is part of the yahoo astra library)
              > <mx:HBox width="100%">
              > <mx:FormItem label="Start Time">
              > <mx:DateField id="startDate" formatString="DD/MM/YYYY"
              > showToday="true"/>
              > </mx:FormItem>
              > <mx:FormItem>
              > <ns1:TimeInput id="startTime" displayTwoDigitHoursValue="true"
              > showSeconds="false" showAMPM="false" useTwelveHourFormat="false"/>
              > </mx:FormItem>
              > </mx:HBox>
              >
              > here is the code for the submit button
              > <mx:FormItem>
              > <mx:Button label="Submit" width="160" height="30" dataChange=""
              > click="getDateTime(startDate.selectedDate,startTime.value)"/>
              > </mx:FormItem>
              >
              >
              > here is my getDateTime function
              > public function getDateTime(d:Date,d1:Date):Date
              > { //here d represents the date and d1 the time component, the time
              > component
              > is working fine
              > var d3:Date=d;
              > var n:Number=d1.getTime();
              > d3.setTime(n);

              In this line you're overwriting the entire date you got from the first
              parameter with the number of milliseconds between midnight, January 1, 1970
              and whatever time was selected in startTime, which will probably be today,
              though you don't share the code for startTime.

              I'd do it like this:

              var d3:Date = new Date(d.fullYear, d.month, d.date, d1.hours, d1.minutes,
              d1.seconds, d1.milliseconds);

              HTH;

              Amy


              • 4. Re: Problem with datefield
                amthekkel Level 1
                HI amy,

                thanks, that did sort out the problem. I had a feeling that setting the time was modifying the date as well but didn't proceed with testing it as i was printing the original date (d ) as shown in my original post and it was displaying today's date and that was confused me. Its working now, so that's one problem sorted.

                I am still stuck with a different problem of using a webservice which i had posted last week and still haven't had any response.
                http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=585&threadid=1388584. Could you be kind enough to have a look and offer any suggestion. I am at wit ends with this one and am really struggling to get this working.

                many thanks,

                regads
                abhi
                • 5. Re: Problem with datefield
                  Level 7

                  "amthekkel" <webforumsuser@macromedia.com> wrote in message
                  news:g9o8e1$j35$1@forums.macromedia.com...
                  > HI amy,
                  >
                  > thanks, that did sort out the problem. I had a feeling that setting the
                  > time
                  > was modifying the date as well but didn't proceed with testing it as i was
                  > printing the original date (d ) as shown in my original post and it was
                  > displaying today's date and that was confused me. Its working now, so
                  > that's
                  > one problem sorted.
                  >
                  > I am still stuck with a different problem of using a webservice which i
                  > had
                  > posted last week and still haven't had any response.
                  >
                  > http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=585&threadid=
                  > 1388584. Could you be kind enough to have a look and offer any suggestion.
                  > I am
                  > at wit ends with this one and am really struggling to get this working.

                  Sorry, I haven't done anything with web services :-)


                  • 6. Re: Problem with datefield
                    amthekkel Level 1
                    ok.. thanks anyway for replying back and for helping me solve the other problem.

                    cheers
                    abhi