MySQL 如何在 Doctrine 2 DQL 中使用 now()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8347872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use now() in Doctrine 2 DQL?
提问by Eduardo
$ php app/console doctrine:query:dql 'SELECT NOW()'
[Doctrine\ORM\Query\QueryException] [Syntax Error] line 0, col 7: Error: Expected known function, got 'now'
[Doctrine\ORM\Query\QueryException] [语法错误] 第 0 行,第 7 列:错误:预期已知函数,得到“现在”
How can I use MySQL's NOW()
function with Doctrine's DQL?
如何NOW()
在 Doctrine 的 DQL 中使用 MySQL 的功能?
回答by Benjamin
The equivalent of MySQL's NOW()
is Doctrine DQL's CURRENT_TIMESTAMP()
.
MySQL 的等价物NOW()
是 Doctrine DQL 的CURRENT_TIMESTAMP()
.
CURRENT_DATE()
only returns the date part.
CURRENT_DATE()
只返回日期部分。
Reference: DQL date/time related functions