Php 无效的日期格式
在laravel 5.8中,我需要为当月制作过滤器,我会:Php 无效的日期格式,php,laravel,Php,Laravel,在laravel 5.8中,我需要为当月制作过滤器,我会: $start_date = new DateTime('first day of this month'); $start_time = clone $start_date->setTime(0, 0, 0); $end_date = new DateTime('last day of this month'); $end_time = $end_date->setTime(23, 59, 5
$start_date = new DateTime('first day of this month');
$start_time = clone $start_date->setTime(0, 0, 0);
$end_date = new DateTime('last day of this month');
$end_time = $end_date->setTime(23, 59, 59);
哪种是设置日期时间格式的有效方法
谢谢 您可以尝试以下方法:
$startDate=新日期时间(“本月第一天”);
$endDate=新日期时间(“本月最后一天”);
ExampleModel::query()
->其中(\DB::raw('DATE(created_at')),[$startDate->format('Y-m-d'),$endDate->format('Y-m-d'));
您试图调试该问题的原因是什么?您是否检查了$start\u time->date
包含的内容,以及date
所需的输入格式?为什么不使用$start\u time->date->format()
来格式化DateTime
?什么是$start\u time->date
DateTime
没有这样的属性,PHP应该为此向您发出通知。
->whereRaw( "created_at >= '" . date ('Y-m-d H:i:s', $start_time->date) . "' and created_at <= '" . date ('Y-m-d H:i:s', $end_time->date) . "' ")
AND created_at >= '1970-01-01 00:00:00'