4 Replies Latest reply on May 3, 2010 7:03 PM by Mara G.

    Need some help with date

    Mara G.

      Hi everyone!

       

      I have an application in Flex AIR and I'm having problems with dates, I could't found an example on internet until now.

       

      I tried this for insert (database is embeded sqlite)

      insertManager.parameters[":mydate"] = mydate.selectedDate.time; // type of this column is INTEGER (in my table) and store a number (milliseconds from 1/1/1970) ex: 1265079600000

       

      Then when I need read records

      mydate.selectedDate = new Date(mydateprice); //it supposed show me DD/MM/YYYY but in every case display 1/1/1970

       

      If I replace mydateprice for mydate.selectedDate = new Date(1265079600000); // it brings me the right date

       

      So I don't know what happed, and I'm not sure if it's the best idea to store a date in Flex AIR

      I'll appreciate any help, information or example to find a solution.

       

      Regards!

      Mara.-

        • 1. Re: Need some help with date
          Vikash.kumar29 Level 3

          It seems to be a dataType issue, Coz time of selected date which you are storing in the Integer field may goes beyond range of integer and its giving you wrong value while accessing it back.

           

          insertManager.parameters[":mydate"] = mydate.selectedDate.time; // type of this column is INTEGER (in my table) and store a number (milliseconds from 1/1/1970) ex: 1265079600000

           

          Try to change the dataField of this column to Number.. This may solves your problem.

           

          Hope this helps you

          - Vikash

          • 2. Re: Need some help with date
            Mara G. Level 1

            Thank you so much VIKASH!!! it works!!!

             

            Now I'm trying to format this value 1265079600000 in my datagrid column:

             

            <mx:DateFormatter id="dateFormatter" formatString="DD/MM/YYYY"/>

            <mx:DataGridColumn width="140" textAlign="left" headerText="DATE" dataField="myDateColumn" labelFunction="formatDate"  />



            public function formatDate(item:Object,column:DataGridColumn):String

            {

            return dateFormatter.format(item.myDateColumn);

            }

             

            but this column appear empty....

             

            Regards and thanks again!

            Mara.-

            • 3. Re: Need some help with date
              Vikash.kumar29 Level 3

              HI Mara,

               

              What does item.myDateColumn contains, Does it contain Date or time of date?. If its contains time(Number) then you need to first convert it into date object. like

               

              public function formatDate(item:Object,column:DataGridColumn):String

              {

                     var mydate:Date = new Date(item.myDateColumn);

                     return dateFormatter.format(myDate);

              }


               

              Hope this helps you in formatting date columbn according to your requirements.

               

              Cheers

              -Vikash

              • 4. Re: Need some help with date
                Mara G. Level 1

                Thank u so much VIKASH!!! again!

                It solved my problem...