how to use mysql now() function in cakephp for date fields?(如何在 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() 函数作为日期字段?
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
