views:

17

answers:

2

More problems with dates.

Basically I'm trying to populate a table with some datetime values from Zend. The datatype of the column that I'm trying to populate is 'datetime'. However, no matter which constant I try the column is always populated with zeroes. I've tried Zend_Date::ISO_8601, Zend_Date::DATETIME, Zend_Date::now() to no avail. Pleas help.

Here's the code:

           if(!$exists){
                $date_time = Zend_Date::DATETIME;
                /*
                 * Create the new site record
                 */
                $site_row = $site_table->createRow();
                //if(isset($n_r['id']))    $row->id  = $n_r['id'];
                $site_row->name         = $n_r['name'];
                $site_row->active       = 1;

                $site_id = $site_table->total() + 1;
                $address_id = $address_table->total() + 1;

                $site_row->id       = $site_id;
                $site_row->address_id       = $address_id;

                /*
                 * Create the address record to go with it
                 */
                $address_row = $address_table->createRow();
                $address_row->postcode = $n_r['postcode'];
                $address_row->address_line1 = $n_r['name'];
                $address_row->start_date = $date_time;

                $address_row->id = $address_id;
                $address_row->save();
                $array[] = $site_row->toArray();
                $site_row->save();

                /*
                 * Create the new site2address record to go with it
                 */
                $site2address_row = $site2address_table->createRow();
                $site2address_row->site_id = $site_id;
                $site2address_row->address_id = $address_id;
                $site2address_row->start_date = $date_time;
            }else{
                $array[] = $exists;
            }
+1  A: 

mySQL expects input for DATETIME columns to be

YYYY-MM-DD HH:MM:SS

independent from the locale you are using. I can't see a Zend constant for that, you may need to format it yourself.

Pekka
how would I do that?
Tunji Gbadamosi
@Tunji here is an example: http://www.eatmybusiness.com/food/2009/01/31/how-to-get-zend-date-in-sql-timestamp-format-eg-mysql-yyyy-mm-dd-hhmmss/90/ (the second one, getting a date *from* ZF)
Pekka
Thanks for your help. I appreciate it.
Tunji Gbadamosi
A: 

you can use mysql function like NOW() for more convenience way. if you are at mysql code bellow may work for you.

  $address_row->start_date = new Zend_Db_Expr('NOW()');
Swing Magic