2 Replies Latest reply on Feb 6, 2011 6:18 AM by fldev11

    date question

    fldev11

      Hello,

       

      Basically I have a datagrid in a flex application connecting to a mysql database and I want to store only the future and current dates in this datagrid, at the moment I seem to be getting the correct year to display, so only dates from 2011 display but the month or day of the month don't seem to be working as well.

       

      I have tried to match the mysql format which is YYYY-MM-DD but to no prevail.

       

      Here is the code I have whipped up so far...

       

      public var dateNew:Date=new Date();

       

      var stringDate = String(dateNew.fullYear+"-"+(dateNew.month+1)+"-"+dateNew.date);- I have tried to match the date format stored in the mysql database, so that I could compare the two dates and then display only the current and future dates.

       

      if(item.date(date displayed in datagrid)>= stringDate) {
                      return true;
                  }
                  else
                  {
                      return false;

       

      Can anyone tell me how to only display the current or future dates? If anyone could be assistance, it would be a great help.

       

      Thanks

        • 1. Re: date question
          Pablo Souza Level 3

          Hi there!

           

          Take a look at the code below, I believe it can help you comparing the database's date with current date.

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/mx">
          <fx:Script>
            <![CDATA[
            
             protected function button1_clickHandler(event:MouseEvent):void
             {
              var currentDate:Date = new Date();
              currentDate.setHours(0,0,0,0);
              var selectedDate:Number = Date.parse(date.text);
             
              if(currentDate.valueOf() > selectedDate.valueOf())
              {
               result.text = "you dont wanna show this date";
              }
              else
              {
               result.text = "you wanna show this date";
              }
             }

            ]]>
          </fx:Script>

          <s:layout>
            <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>
          </s:layout>

          <s:Label text="YYYY/MM/DD"/>
          <s:TextInput id="date" text="2011/02/01"/>
          <s:Button label="Compare with current date" click="button1_clickHandler(event)" />
          <s:Label id="result" />

          </s:Application>

           

           

           

          Hope it helps you!

           

           

          Best regards,

          Pablo Souza

           

          • 2. Re: date question
            fldev11 Level 1

            Thanks for this will try later.