Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无效的日期格式_Php_Laravel - Fatal编程技术网

Php 无效的日期格式

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

在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, 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'