11 Replies Latest reply on Aug 23, 2006 10:58 AM by ntsiii

    formatString in a DateField

    zax_srb
      Hi.

      When I use the following code to format the date in a dateField:

      <mx:DateField showToday="true" enabled="true" themeColor="#0080ff" formatString="DD,MMMM,YYYY" />

      the date displayed is (for the 23rd August, 2006): 23,0808,2006
      The mask doesn't seem to work.... Am I doing something wrong?

      Thanks,
      Stephen


        • 1. Re: formatString in a DateField
          dwischusen
          Why do you have MMMM for the month? Shouldn't it be MM?
          • 2. Re: formatString in a DateField
            zax_srb Level 1
            According to the documentation for formatString:
            Month in year. The format depends on the following criteria:

            * If the number of pattern letters is one, the format is interpreted as numeric in one or two digits.
            * If the number of pattern letters is two, the format is interpreted as numeric in two digits.
            * If the number of pattern letters is three, the format is interpreted as short text.
            * If the number of pattern letters is four, the format is interpreted as full text.

            Examples:
            M = 7
            MM= 07
            MMM=Jul
            MMMM= July

            and I want to use the full text for month.
            • 3. Re: formatString in a DateField
              ntsiii Level 3
              I just tried it and "MMMM" definitely does not behave as advertised.

              Neither does "MM"

              Looks like a bug. You might want to report it.
              http://www.macromedia.com/support/email/wishform/

              Tracy
              • 4. Re: formatString in a DateField
                ntsiii Level 3
                It seems that the formatString is seriously broken or we are missing something.

                E, EE, EEE, EEEE, H,J,K, N, NN, A do not work, they just return the letters.

                I'll look around some more.

                Tracy
                • 5. Re: formatString in a DateField
                  zax_srb Level 1
                  OK, I have reported the bug, and we will see what happens. If anyone figures this out in the meantime, please let me know.

                  Many Thanks,
                  Stephen
                  • 6. Re: formatString in a DateField
                    zax_srb Level 1
                    OK, got the following response from Adobe (VERY quickly)....

                    No Stephen,

                    It's not a bug.

                    DateField is not the same as the date formatter. You can give a date and
                    get it formatted to the desired format using the date formatter. If you
                    look into the DateField documentation you'll find that no such thing is
                    mentioned with Date Field - DD MMMM YYYY. So you'll have to write your
                    function to format the date and display it.

                    So you can do something like this...

                    <?xml version="1.0" encoding="iso-8859-1"?> <mx:Application
                    xmlns:mx=" http://www.adobe.com/2006/mxml" width="600" height="600"
                    backgroundColor="white" >

                    <mx:Script>
                    <![CDATA[

                    private function formatDate():void
                    {
                    formatted1.text =
                    df.format(dateComp.selectedDate);
                    df1e.text=df.error;
                    }
                    private function formatMe():void
                    {
                    myDateF.text = df.format(myDateF.selectedDate);
                    df1e.text=df.error;
                    }
                    ]]>
                    </mx:Script>
                    <mx:DateFormatter id="df" formatString="DD MMMM YYYY" />

                    <mx:HBox horizontalAlign="center" width="100%" borderStyle="solid">
                    <mx:Label text="No Format String" fontSize="20"
                    fontWeight="bold" /> </mx:HBox>

                    <mx:HBox horizontalAlign="center" width="100%" borderStyle="solid">
                    <mx:TextArea wordWrap="true" width="100%" text="Select a date
                    using the DateChooser. Press &quot;Execute Formatting&quot; to format
                    the date. Verify selected date is formatted using the default
                    MM/DD/YYYY formatString." /> </mx:HBox>


                    <mx:Form>
                    <mx:FormItem label="Input">
                    <mx:DateChooser id="dateComp" />
                    </mx:FormItem>
                    <mx:FormItem label="Output">
                    <mx:TextInput id="formatted1" editable="false" text="Not yet
                    set!" width="100%" />
                    </mx:FormItem>
                    <mx:FormItem label="Error">
                    <mx:TextInput id="df1e" text="" />
                    </mx:FormItem>
                    <mx:FormItem>
                    <mx:Button label="Execute Formatting" click="formatDate();" />
                    </mx:FormItem>
                    <mx:FormItem>
                    <mx:DateField id="myDateF" change="formatMe()"
                    formatString="DD MMMM YYYY" />
                    </mx:FormItem>
                    </mx:Form>

                    </mx:Application>

                    Hope this helps,
                    -sam

                    I think I get it now, but I don't think it is very intuitive.

                    Stephen
                    • 7. Re: formatString in a DateField
                      flexsam Level 1
                      In the line <mx:DateField id="myDateF" change="formatMe()"
                      formatString="DD MMMM YYYY" />
                      I was just testing to see what results were being reported. Actually the format string needn't be set if a function is being used to set the text of the DateField.

                      Thanks,
                      -sam
                      • 8. Re: formatString in a DateField
                        ntsiii Level 3
                        Wait a minute. The docs for DateField list the formatString property, and the doc for that property directly references the listing for DateFormatter. Anyone who is trying to use the DateField by following the docs will expect formatString to behave the same as for DateFormatter.

                        If the formatString property on DateField takes different values than the formatString property on the DateFormatter, what are they?

                        This is either a bug in the control, or it is a bug in the documentation.

                        I'll put a note in LiveDocs.

                        Tracy
                        • 9. Re: formatString in a DateField
                          ntsiii Level 3
                          Ahh, ok, I read the doc again and see this:
                          "This property can contain "M", "D", "Y", delimiter, and punctuation characters"

                          The fact that the name is the same and that there is a link to the DateFormatter.formatString doc is very misleading.

                          It still warrants a note in LiveDocs.

                          Maybe one of the extended component gurus will make a version of DateField that uses dateString fully.

                          Tracy
                          • 10. Re: formatString in a DateField
                            ntsiii Level 3
                            Still ranting...
                            The statement:
                            "This property can contain "M", "D", "Y", delimiter, and punctuation characters",

                            follwed by the statement:
                            The default value is "MM/DD/YYYY",

                            by reasonable extension implies that "DD MMMM YYYY" should be legal.

                            So we still do not know the rules for DateField.formatString.

                            Tracy
                            • 11. Re: formatString in a DateField
                              ntsiii Level 3
                              Ok, the valid datepart values for format string are as follows:
                              MM = 2 digit month
                              DD = 2 digit day of month
                              Y, YY = 2 digit year
                              YYY, YYYY = 4 digit year

                              Any other value will corrupt the display.

                              Tracy