8 Replies Latest reply on Oct 20, 2006 7:55 AM by Like2Flex

    Date Display in DateField

    Like2Flex Level 1
      Hi,

      Am trying to get a date into my DateField controls from my table in my database.
      Does not seem to work.
      Pls see the code below and give me a hint of what is going wrong.
      Pls note that when am outputting the query in browser its working fine.

      But the flex side is not !!.

      //cfc
      <cffunction name="getLastDate" access="remote" returntype="query">
      <cfquery name="qlastdate" datasource="test">
      Select tbl_ords.my_date as thelastdate
      from tbl_ords
      order by tbl_ords..my_date desc limit 1
      </cfquery>
      <cfreturn qlastdate>
      </cffunction>




      //flex code
      public function getLastDate(event:ResultEvent):void
      {
      lastdate=event.result as String;
      specific_df.dataProvider=lastdate;
      specific_df.data="thelastdate";
      //Alert.show(String(lastdate));
      }


      Thx
        • 1. Re: Date Display in DateField
          peterent Level 2
          Instead of having your cffunction have returntype="query", try changing it to returntype="any".

          I think this will make event.result an actual Date ActionScript object if that is what the cffunction ultimately returns. If it is a Date, then you can do:

          specific_df.selectedDate = event.result as Date;

          assuming specific_df is your DateField.
          • 2. Re: Date Display in DateField
            Like2Flex Level 1
            Hi I tried, but am getting "null" in my Alert. But the query is ok. I checked it, it is wokring fine. Prob is in flex.

            [Bindable]
            public var lastdate:String= new String(); //My variable declaration


            public function getLastDate(event:ResultEvent):void
            {
            //lastdate=event.result as String;
            //specific_df.dataProvider=lastdate;
            specific_df.selectedDate = event.result as Date;
            //specific_df.data="thelastdate";
            Alert.show(String(specific_df.selectedDate));
            }


            Pls some more hints. Thx
            • 3. Re: Date Display in DateField
              netageadv
              Hi guys,
              tnks :)
              In a first moment I casted my value but i had some troubles with date formatting, so I tried to have a timestamp in my item and manage it.
              Going back on my steps and thanks to you I've casted my value again and figure out what was going wrong....

              • 4. Re: Date Display in DateField
                Like2Flex Level 1
                But any solution for my problem ??
                • 5. Re: Date Display in DateField
                  peterent Level 2
                  Inside your getLastDate function, what is the data type of event.result? Is it a string? a number? If a number, what does it represent? For example, if October 16, 2006 is represented as 20061016 that won't do as a Date. You would have to parse this into year, month, date and then create a Date object from that.
                  • 6. Re: Date Display in DateField
                    Like2Flex Level 1
                    Hello,

                    I've defined returntype as "any as you suggested.
                    The query below is fine, its giving me the right date.

                    <cffunction name="getLastDate" access="remote" returntype="any">
                    <cfquery name="qlastdate" datasource="mysource">
                    Select date_format(tbl_ords.my_date,'%d/%m/%Y') as lastdate
                    from tbl_ords
                    order by tbl_ords.my_date desc limit 1
                    </cfquery>
                    <cfreturn qlastdate>
                    </cffunction>

                    When I go to flex,my code is as follows:

                    lastdate=event.result as String;
                    specific_datefld.dataProvider=lastdate;
                    //specific_datefld.data =event.result as Date;
                    specific_datefld.data=new Date("lastdate");
                    Alert.show(lastdate)
                    .

                    Its giving me NaN/NaN/NaN.

                    Using new Date as well does not convert it to date to be displayed in my DateField.
                    Let me know how I can do it?

                    Thx
                    • 7. Re: Date Display in DateField
                      peterent Level 2
                      As I recall from SQL, doing:

                      date_format(tbl_ords.my_date,'%d/%m/%Y') as lastdate

                      is formatting the datetime value as a string and placing that in the query result. In other words, you do not have a datetime entity any more, you have a string now. Which is what is being returned to Flex. Something like "20/10/2006". This is not a date, it is a string.

                      So the Flex code needs to accept a string. Using "as Date" won't work because you no longer have a Date in the result.

                      It would be easier to figure out if you use the Flex Builder 2 debugger and set a breakpoint in your Flex code so you could examine what event.result really is. The debugger will tell you the data type and you can see the value for yourself. Then you'll be able to make a decision about how to handle this.
                      • 8. Re: Date Display in DateField
                        Like2Flex Level 1
                        Ok thk, I learnt something new...will try it tomorrow and let you know.

                        Many thx