There's no conversion needed. Date's sent from ColdFusion become ActionScript 
date objects.
What you need to do is call the DateFormatter.format method when needed, 
passing it the Date object.

Here's an example of a RemoteObject fetching news from a MySQL database, which 
contains:
- newsHeader (string)
- newsText (text)
- newsDate (date)

The results are displayed in a List instance (news_list).
When an item is selected in the list, it displays the date (newsDate) of the 
selected item in a label (newsDate_label) instance.
Instead of just displaying the date, it calls the format() method of the 
DateFormatter:
-->    newsDate_fmt.format(this.news_list.selectedItem.newsDate)


 <mx:RemoteObject id="newsSelect_ro"
    destination="ColdFusion"
    source="path.to.service.NewsSelect"
    >
    <mx:method name="getNews" />
 </mx:RemoteObject>

<mx:DateFormatter id="newsDate_fmt"
    formatString="EEEE, DD MMMM YYYY"
    />

<mx:List id="news_list"
    dataProvider="{newsSelect_ro.getNews.lastResult}"
    labelField="newsHeader"
    />

<mx:Label id="newsDate_label"
    text="{newsDate_fmt.format(this.news_list.selectedItem.newsDate)}"
    />

regards,
Muzak

----- Original Message ----- 
From: "Adam Royle" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, March 20, 2007 11:56 AM
Subject: Re: [flexcoders] Flex dates


Hi Jeremy,

I recommend converting your date into a native actionscript date object. This 
has many benefits which include all of the date 
manipulation methods available, the dateformatter class, correct date sorting 
in the datagrid, etc.

You can use

var date_from_db:String = "";
var d:date = new Date();
d.setTime(Date.parse(date_from_db));


Where date_from_db would equal one of the following string formats.

MM/DD/YYYY HH:MM:SS TZD
HH:MM:SS TZD Day Mon/DD/YYYY
Mon DD YYYY HH:MM:SS TZD
Day Mon DD HH:MM:SS TZD YYYY
Day DD Mon HH:MM:SS TZD YYYY
Mon/DD/YYYY HH:MM:SS TZD
YYYY/MM/DD HH:MM:SS TZD

I'm not familiar with CF but the way I do it in PHP using MySQL is in this SQL 
query. The 'start_time' column is a datetime.

SELECT replace(start_time,'-','/') as start_time FROM mytable



In another project where I only receive the date in the format 'YYYY-MM-DD', I 
use my own parseDate() method.


public function parseDate(s:String):Date
   {
    if (!s) return null;
    var a:Array = s.split('-');
    return new Date(parseInt(a[0]),parseInt(a[1])-1,parseInt(a[2]));
   }



you would use it like:


var d:Date = parseDate('2007-01-01');


Hope this helps.

Cheers,
Adam


  ----- Original Message ----- 
  From: Roman Protsiuk
  To: [email protected]
  Sent: Tuesday, March 20, 2007 7:16 PM
  Subject: Re: [flexcoders] Flex dates


  Formatter will "do that" only for displaying your date. And how it comes out 
of database depends on database interface. In general 
you receive some standardized date/time. If you want to get specifically 
formatted date out of the database you should ask database 
to do it. Though I can't imagine why one may need that kind of formatting.

  R.



  On 20 Mar 2007 01:47:16 -0700, flexjeremy <[EMAIL PROTECTED]> wrote:
    Hi guys,

    I am new to flex and have been having a huge learning curve. So be
    gentle. I'm kinda new to REAL OO. But I know CF very well. So with
    that said I'm stuck on dates.

    I am trying to format a date coming out of a database so it will
    look pretty. i.e. dd/mm/yyyy

    I have an <mx:datefield id="DateIn"
    text="remoteService.qryDrawdown.lastResult[0].DateIn"
    formatString="DD/MM/YYYY"></mx:datefield>

    Now I know that the formatString paramater does that for when you
    choose it but how do you format it coming out of the database.
    Currently its "Tue Feb 28 00:00:00 GMT" etc etc.

    I found the <mx:dateFormater> tag but haven't been able to get it
    working correctly.

    Any Advise would be great!!

    Jeremy








Reply via email to