4 Replies Latest reply on Sep 13, 2010 10:59 AM by Jerry62712

    How do I format a date

    Jerry62712 Level 1

      When I populate several date fields from a database I find they have different formats (alpha month sometimes and not others for example).  I'd like to force all dates from the database to be in mm/dd/yyyy format.  I tried adding that as the formatString property, but that only seemed to work when the user enters the date, not if it is populated from a database.


      I got this pseudocode from a friend who isn't around this week:

      <DateValidator source="{dateInput}'
                      requiredFieldError="Date field is not selected"

      //formatter for the date

      private var valResult:ValidatorResultEvent
      private function dateFormatting():void
      valResult = myDateValidator.validate();
      if(valResult.type == ValidatorEvent.Valid)
      //do something
      textInput.text  = dateFormatter.format(textInput.text);
      //do something

      //formatter for the date
      <DateFormatter id="dateFormatter" inputString="MM/DD/YYYY"/>

      I would read that as:

      1) set up a DateValidator with an input to be determined

      2) set up a validation event

      3) set up a function ...

      4) set up a DateFormatter with the layout


      I don't see how the function gets invoked anywhere.  I also don't see how the specific date (and there are a lot of them) gets passed to the validator.  It looks like a variable (dateInput) is set somewhere and bound to the validator, but I don't see where.


      I'm assuming that once the function is called, the "valResults" gets the event that of the validation.  And if that event is a valid date only needing formatting then the date formatter object is invoked.  If it is not valid then a DateValidator error message pops up.


      This process would be applied to five different components that are included in the system.  Each may have one to 12 dates included in the component.