1 Reply Latest reply on Nov 12, 2008 8:31 AM by EvolvedDSM

    Capturing user-input time as date/time ?

    EvolvedDSM Level 2
      I need to allow users to enter time into an appointment application I'm creating. I need the value of the input to be stored as a Date-type in my db table. So far I've created an hour and minutes text input, and a combo box AM/PM selection. Since Flex doesn't have any time-based input components similar to dateField, this is the only way I've been able to correctly capture time.

      I have variable = hour.text + ':' +minute.text + ' ' +ampm.text to put the time in a string format. This works, but now I don't know how to convert it from string to date.

      Any suggestions on how to handle this? thanks
        • 1. Re: Capturing user-input time as date/time ?
          EvolvedDSM Level 2
          Nevermind. Figured it out. For those that want to know...

          declare your time variables...
          var hour:Number
          var minute:Number
          var second:Number
          var ampm:String

          In the function to insert the time into your db table, set/convert each to the text input strings...
          hour = Number(hourInput.text)
          minute = Number(minInput.text)
          second = Number(secInput.text)
          ampm = ampmInput.text // no conversion needed

          In your insert function, declare a variable to hold your time object
          var mytime:Date = new Date();

          use the attributes of the object to set the hour, minutes, seconds, am/pm. The am/pm is tricky -- there is no attribute for this, so you have to set the hour as if it were military time (24 hour), like so...

          if(ampm.text = 'am'){
          mytime.hours = hour;
          }else{
          mytime.hours = hour + 12;
          }
          mytime.minutes = minute;
          mytime.seconds = second;

          Finally, set your time column = mytime;

          I happen to use a valueObject for my table (myVO), so I would set the column 'thetime' to...
          myVO.thetime = mytime;

          Hope this helps others!