我想查询在2016-01-10创建的用户。所以在laravel 5.1中的代码如下(创建的是时间戳):
$day1 = new Carbon();
$day1->year = 2016;
$day1->month = 1;
$day1->day = 10;
$day2 = new Carbon();
$day2->year = 2016;
$day2->month = 1;
$day2->day = 11;
User::whereBetween('created_at', [$day1->startOfDay(), $day2->startOfDay()])->get();
上面的代码工作正常。
但这种正常的方式不会:
User::whereBetween('created_at', [$day1->startOfDay(), $day1->endOfDay()])->get();
我觉得没有区别。
最佳答案
你不需要中间人:
$myDate = new Carbon('2016-01-10');
User::whereDate('created_at', '=', $myDate->format('Y-m-d'))->get();