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() 函数作为日期字段?
基础教程推荐
- Sql Server 字符串到日期的转换 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01