Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting current date to MySql using Zend Date

I have a website based on Zend Framework. There is a form for users to fill in and the entered data is inserted in the database.

The users don't enter the date/time. I would like to populate the data value based on the current date/time . The date field is of type datetime.

i'm constantly getting the following error message:

Notice: Array to string conversion in D:\wamp\www\CNFSORG\library\Zend\Db\Statement\Pdo.php on line 228

I have tried doing the following:

<?php $date = new Zend_Date(); ?>

also tried doing:

<?php $date = new Zend_Db_Expr('NOW()'); ?>
<?php $date = new Zend_Db_Expr('CURDATE()'); ?>

I would be very grateful if someone could point me towards the right direction.

thanks in advance...

like image 963
user949852 Avatar asked Feb 22 '23 20:02

user949852


2 Answers

The Correct answer is

<?php $date = new Zend_Db_Expr('NOW()'); ?>

You can try create a current timestamp from php with something like that

<?php  $date = new \DateTime(); ?>
like image 157
Pablo Morales Avatar answered Feb 25 '23 11:02

Pablo Morales


Well, i'v done this for SqlServer, but i think that for MySql you just need to change the db-expression for the one you want.

$this->_colocation = new Application_Model_Colocation();
$solicitacao = $this->_colocation->find($post['hdnIdSolicitacao'])->current();
$solicitacao->data_chegada = new Zend_Db_Expr('getdate()');
$solicitacao->save();

Hope it helps.

like image 26
Lennon Avatar answered Feb 25 '23 11:02

Lennon