如何只获取laravel中的当前日期和以前的日期?
问题描述:
我想只得到当前的日期和前dates.Here是我怎样努力如何只获取laravel中的当前日期和以前的日期?
$jobseekers = Calllog::orderBy('calllogs.created_at','DESC')
->get()->where('call_back_date', '<=', Carbon::today()->toDateString());
这个节目只有以前的日期,我想both.If我删除“<”,它显示只有当前的日期,请帮我。
答
$jobseekers = Calllog::orderBy('calllogs.created_at','DESC')->where('call_back_date', '<=', Carbon::now())->get();
现在使用(),而不是今天()。与today()不同,now()现在返回完整的日期时间。
另请注意,我在get()之前移动了条件,以防止从数据库获取额外数据。下面雄辩查询
+0
如果使用'now',则下一部分时间(当前时刻之后)的时间与条件不符。 –
答
使用tomorrow
和<
条件
$jobseekers = Calllog::orderBy('calllogs.created_at','DESC')
->get()->where('call_back_date', '<', Carbon::tomorrow()->toDateString());
答
使用
$jobseekers = Calllog::whereDate('call_back_date','<=',Carbon::today)->get()
'碳::今日()'返回00:00:00(小时和分钟)今天几号。试试'Carbon :: now()' –