Laravel ORM,日期比较 [英] Laravel ORM, date compare
本文介绍了Laravel ORM,日期比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel Framework.
I'm using Laravel Framework.
我想要这一天的所有行.这是我尝试过的:
I want all of the rows for this day. This is what I tried:
DB::table('users')->where('created_at', '>=', date('Y-m-d H:i:s'))
(字段created_at
在数据库中以Y-m-d H:i:s
格式表示).
(field created_at
represented in database in format: Y-m-d H:i:s
).
推荐答案
嗯...这个问题似乎已经消失了.*
Hmmm...there was a good answer to this question which seems to have now disappeared.*
是这样的:
User::where('created_at', '>=', new DateTime('today'))
注意:如果要将此代码放入具有名称空间的文件中,或者将来可能使用名称空间,则应在DateTime类的前面加上反斜杠:new \DateTime('today')
.
Note: if you're putting this code in a file with a namespace, or might use a namespace in the future, you should prefix the DateTime class with a backslash: new \DateTime('today')
.
* https://stackoverflow.com/questions/15052679/laravel-framework-how-今日查询
这篇关于Laravel ORM,日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文