如何在 cakephp 中使用 mysql now() 函数作为日期字段?

2021-12-21 00:00:00 date mysql cakephp

我的 cakephp 项目中有此代码:

I have this code in my cakephp project:

$this->data['MyObject']['expire_date'] = 'NOW()';

还有……

$this->MyObject->save($this->data);

但这不会将数据保存在数据库中.谷歌搜索后,我发现我可以像这样使用 now() .但是好像不对,正确的使用方法是什么?

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:我的 MySQL 字段的类型是日期".如果我这样使用它会起作用:

PS: My MySQL field is of type 'DATE'. It works if I use like this:

$this->data['MyObject']['expire_date'] = date( 'Y-m-d', mktime(0, 0, 0, date("m"), date("d")+30,   date("Y")));

推荐答案

$this->data['MyObject']['expire_date'] = DboSource::expression('NOW()');

相关文章