I struggled with this on another project.  Now, this project uses
Cairngorm, value objects, etc., so it's a bit different, but it might
help.

The value object looks as follows (snippet):

        public class UserVO implements IValueObject
        {
                private var _date_added:Date;
                private var _last_login:Date;
                private var _last_modified:Date;
                
                public function get date_added():Date
                {
                        return _date_added;
                }
        
                public function set date_added(value:*):void
                {
                        _date_added = new Date(value);
                }

                public function get last_login():Date
                {
                        return _last_login;
                }
        
                public function set last_login(value:*):void
                {
                        _last_login = new Date(value);
                }
                public function get last_modified():Date
                {
                        return _last_modified;
                }
        
                public function set last_modified(value:*):void
                {
                        _last_modified = new Date(value);
                }               
                public var user_id:Number;
                public var account_id:Number;
                etc....


I use getters/setters for all the date fields using the value that was
passed from the AMFPHP code on the back end.

The MySQL on the backend formats the date as follows (sql):

$sql = DB::getInstance()->prepare("SELECT user_id, account_id,
facility_id, role, email, first, last, title, phone, rca,
date_format(date_added, '%a %b %e %Y %r') as date_added,
date_format(last_modified, '%a %b %e %Y %r') as last_modified
FROM users 
WHERE email = :usr");

It basically takes the output and "fetches" it into the UserVO class
(PHP PDO):

/* fetch results into a UserVo object */
$sql->setFetchMode( PDO::FETCH_CLASS, 'UserVO');

and returns the UserVO.

To try and summarize this:

1.  I used the date_format in MySQL to format the date similar to how
one creates a date in Flash/Flex.  
2.  I used this "string" date field from AMFPHP and create a date
field in Flash/Flex that is used by the application.

I don't think you can pass the MySQL date value straight to Flex and
create a date unless you parse the information in Flex to create the
date field.

It has been awhile, but I seem to remember this working ok.

hth 

Chief
--- In flexcoders@yahoogroups.com, Nik Derewianka <[EMAIL PROTECTED]> wrote:
>
> Hi All,
> 
> Could anyone enlighten me as to how i should send and retrieve date  
> and datetime data for inserting into MySQL via amfphp (1.9) with value  
> objects ?
> 
> If i edit the data directly in MySQL and then retrieve a vo with a  
> Date datatype i get the following message:
> 
> TypeError: Error #1034: Type Coercion failed: cannot convert  
> "1970-01-01" to Date.
> 
> So, I need to format the date in someway so that flex can deserialize  
> it properly. Any insight would be greatly appreciated (am coming  
> from .net land so new to both PHP and as3).
> 
> Cheers,
> Nik
>


Reply via email to