[英]Laravel: WhereBetween Date with request date
i want to get data between two times with dates like this code working我想在两次之间获取数据,日期像这样的代码工作
$jodies = DisawarJodi::whereBetween('created_at', [now()->subDay()->format('Y-m-d') . " 08:00:00", now()->format('Y-m-d') . " 2:50:00"])->get();
but when i use request its not working但是当我使用请求时它不起作用
$date = Carbon::parse($request->date);
$jodies = DisawarJodi::whereBetween('created_at', [$date->subDay()->format('Y-m-d') . " 08:00:00", $date->format('Y-m-d') . " 2:50:00"])->get();
whats wrong with this code这段代码有什么问题
Carbon::parse
can be a little problematic as it does it's best interpretation of the format but can easily get it wrong. Carbon::parse
可能有点问题,因为它是对格式的最佳解释,但很容易出错。
Try Carbon::createFromFormat('Ym-d', $request->date);
试试
Carbon::createFromFormat('Ym-d', $request->date);
This way you are explicit about which character represents what in the date.这样您就可以明确哪个字符代表日期中的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.