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

how to use mysql now() function in cakephp for date fields?(如何在 cakephp 中使用 mysql now() 函数作为日期字段?)

本文介绍了如何在 cakephp 中使用 mysql now() 函数作为日期字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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()');

这篇关于如何在 cakephp 中使用 mysql now() 函数作为日期字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

基础教程推荐