Wednesday, November 7, 2018

cakephp : how to use mysql now() function in cakephp for date fields?

I have this code in my cakephp project:
$this->data['MyObject']['expire_date'] = 'NOW()';
and...
$this->MyObject->save($this->data);
But this won't save data in database. After googling I found I can use now() like this. But it seems wrong, what is the correct way to use it?
PS: My MySQL field is of type 'DATE'. It works if I use like this:

It should be called like this: $db = $this->MyObject->getDataSource(); $this->data['MyObject']['expire_date'] = $db->expression('NOW()'));

No comments:

Post a Comment