Laravel雄辩的日期等于或大于DateTime [英] Laravel eloquent where date is equal or greater than DateTime
问题描述
我正在尝试从日期列高于或等于当前时间的模型中获取关系数据。
I'm trying to fetch relational data from a model where the date column is higher or equal to the current time.
日期列的格式如下: Ymd H:i:s
The date column is formated as this: Y-m-d H:i:s
我要做的是抓取Ymd H:i:s将来的所有行。
What I'm trying to do is to grab all rows where the Y-m-d H:i:s is in the future.
示例:假设日期为2017-06-01,时间为09:00:00
然后我想获取日期所在的所有行在未来,时间在未来。
Example: lets assume the date is 2017-06-01 and the time is 09:00:00 Then i would like got all rows where the date is in the future, and the time is in the future.
当前,我的代码看起来像这样,并且几乎可以正常工作,但是它无法捕获日期为当前日期的行。
Currently my code looks like this, and it's almost working but it doesn't grab the rows where the date is the current day.
public function customerCardFollowups() {
return $this -> hasMany('App\CustomerCardFollowup', 'user_id') -> whereDate('date', '>', Carbon::now('Europe/Stockholm')) -> orderBy('date', 'asc') -> take(20);
}
我在做什么错?
预先感谢。
What am I doing wrong? Thanks in advance.
推荐答案
听起来像您需要使用> =
,例如:
Sounds like you need to use >=
, for example:
->whereDate('date', '>=', Carbon::now('Europe/Stockholm'))
这篇关于Laravel雄辩的日期等于或大于DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!