Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store timestamp in db with Zend_Date?

I keep trying to insert a timestamp to the db with $rowUser->fecha = new Zend_Date(); but when I check the db I always find '0000-00-00 00:00:00' in that field.

I added the 'fecha' column (the one with the timestamp) with a MySQL ALTER statement, so maybe that's the prolem...I don't know. Not sure if it's my zend or SQL which is failing. Please Mods, don't close the thread if the question seems vague, I'll change or look for more info if necessary.

like image 532
la_f0ka Avatar asked Nov 20 '25 08:11

la_f0ka


2 Answers

Well for whoever may care about this or may have a similar issue in the future I've found a way around this. In the user model:

$rowUser = $this->createRow();

    if($rowUser) {
        // update the row values
        $rowUser->email = $email;
        $rowUser->password = md5($password);
        $rowUser->url = $url;
        $rowUser->responsable = $responsable;
        $rowUser->role = $role;
        $rowUser->fecha = Zend_Date::now()->toString('yyyyMMddHHmmss');; // This is the important bit
        $rowUser->save();
        //return the new user
        return $rowUser;
    } 

you could also use $rowUser->fecha = new Zend_Db_Expr('NOW()'); but that might be troublesome if there's a db migration.

like image 174
la_f0ka Avatar answered Nov 22 '25 03:11

la_f0ka


I believe you'll need to use something similar to

$rowUser->fecha = new Zend_Db_Expr('NOW()');

I think you can use the Zend_Date component, but you'll have to convert it to the correct format as a string representation to insert.

like image 41
jcarouth Avatar answered Nov 22 '25 03:11

jcarouth