4 Replies Latest reply on Sep 5, 2006 10:19 AM by

    MySQL and dates

      When you extract xml from a MySQL database you get the following format for a date: 2006-08-29T21:01:07.0000000-07:00
      I have managed to get flex to connect to the XML file, display all the items in the XML file, to include the above mentioned date. But the problem comes in formatting that date. Obviously I don't want the user staring at that mess but all my feeble attempts to format it in Flex haven't produced any results. I tried to tackle the whole thing but all that did is turn the jumbled mess into an empty column so I tried to go simple and just pull the year (as shown below) and I still get nothing in that column. Does anyone have any ideas on how to approach this?


      <mx:DateFormatter id="DateDisplay" formatString="YYYY" />
      ....
      <mx:DataGridColumn headerText="Last Access" dataField="{DateDisplay.format(users_request.lastResult.last_access)}" sortDescending="true"/>
        • 1. Re: MySQL and dates
          Use an itemRenderer to format the data, i.e.:

          <mx:DataGridColumn dataField="startDate" headerText="Start Date">
          <mx:itemRenderer>
          <mx:Component>
          <mx:VBox>
          <mx:DateFormatter id="dateFormatter" formatString="YYYY"/>
          <mx:Text text="{dateFormatter.format(data.startDate)}"/>
          </mx:VBox>
          </mx:Component>
          </mx:itemRenderer>
          </mx:DataGridColumn>
          • 2. MySQL and dates
            alright so using your idea i have the following:

            <mx:DataGridColumn dataField="last _access" headerText="Last Access">
            <mx:itemRenderer>
            <mx:Component>
            <mx:VBox>
            <mx:DateFormatter id="dateFormatter" formatString="YYYY"/>
            <mx:Text text="{dateFormatter.format(users_request.lastResult.last_access)}"/>
            </mx:VBox>
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>

            but now I am getting the following error message:
            Severity Description Resource In Folder Location Creation Time Id
            2 1120: Access of undefined property users_request. Statistics.mxml Statistics line 24 September 1, 2006 1:41:33 PM 15



            so apparently it won't let me access that data in the same manner as I did in my first example. So i thought maybe if I gave the datagrid an id and then accessed it via that I might have better results:
            <mx:DataGrid id="mygrid" .....\>
            .....
            <mx:Text text="{dateFormatter.format(mygrid.last_access)}"/>
            Severity Description Resource In Folder Location Creation Time Id
            2 1120: Access of undefined property mygrid. Statistics.mxml Statistics line 24 September 1, 2006 1:34:54 PM 14

            But I get a similiar error message as before. Any idea what I'm missing?
            • 3. MySQL and dates
              Just use
              <mx:Text text="{dateFormatter.format(data.last_access)}"/> instead.
              You are inside the datagrid logic, and as it goes thru the several rows of your users_request dataservice, the "data.last_access" contains the value for that row.
              I am assuming here that the DateFormatter.format() API might need clarification about the existance of a "data" property that can be used in this context. Please let me know if this works for your "last_access" column, and I will let the doc team know our findings.

              Thanks,
              Jorge
              • 4. Re: MySQL and dates
                Alright, that worked like a charm and now I have the exact formatting that I want, but now I've noticed another issue. I tried to auto sort that "Last Access" column but it doesn't seem to work. The datagrid just loads the entries in some random order. But when you click on the header then it sorts the dates in order. How do I get it to sort them the way I want it on load? (see current coade below)

                <mx:DataGridColumn dataField="last_access" headerText="Last Access" editable="false" sortDescending="true">
                <mx:itemRenderer>
                <mx:Component>
                <mx:VBox>
                <mx:DateFormatter id="dateFormatter" formatString="H:NN:SS A MM-DD-YYYY"/>
                <mx:Text text="{dateFormatter.format(data.last_access)}"/>
                </mx:VBox>
                </mx:Component>
                </mx:itemRenderer>