碳和雄辩的时代
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了碳和雄辩的时代相关的知识,希望对你有一定的参考价值。
我想显示在特定时间内输入的所有条目,从27-02-2018 22:00:00到28-02-2018 05:59:59,这是我到目前为止所得到的,但我没有得到从网页上返回的任何结果
$NightStart='22:00:00';
$NightEnd='05:59:59';
$dcmlogs = log::with('users')->whereBetween('created_at',['Carbon::today()->toDateString() $NightStart','Carbon::yesterday()->toDateString() $NightEnd'])->paginate(10);
为什么我没有得到任何结果?我确信在数据库中有一些带有这些时间戳的行。
答案
php不会仅在'
内部解析"
中的值:
尝试:
$NightStart = '22:00:00';
$NightEnd = '05:59:59';
$today = Carbon::today()->toDateString() . ' ' . $NightStart;
$yesterday = Carbon::yesterday()->toDateString() . ' ' . $NightEnd;
$dcmlogs = log::with('users')->whereBetween('created_at',[$yesterday, $today])->paginate(10);
另一答案
尝试更改此行:
$dcmlogs = log::with('users')->whereBetween('created_at',['Carbon::today()->toDateString() $NightStart','Carbon::yesterday()->toDateString() $NightEnd'])->paginate(10);
至:
$fromTime = Carbon::yesterday()->toDateString()." $NightEnd";
$toTime = Carbon::today()->toDateString()." $NightStart";
$dcmlogs = log::with('users')
->whereBetween('created_at', [$fromTime, $toTime])
->paginate(10);
另一答案
如果您希望完全使用Carbon,可以使用以下内容:
$dcmlogs = log::with('users')->whereBetween('created_at',[
Carbon::yesterday()->hour(5)->minute(59)->second(59)->toDateTimeString(),
Carbon::today()->hour(22)->toDateTimeString()
])->paginate(10);
或者,您也可以使用setTime($h, $m, $s)
而不是手动设置条件
$dcmlogs = log::with('users')->whereBetween('created_at',[
Carbon::yesterday()->setTime(5, 59, 59)->toDateTimeString(),
Carbon::today()->setTime(22, 0, 0)->toDateTimeString()
])->paginate(10);
您使用单引号的示例,它将您的条件解析为字符串,但也没有正确附加。
以上是关于碳和雄辩的时代的主要内容,如果未能解决你的问题,请参考以下文章