我想查询在2016-01-10创建的用户。所以Laravel 5.1中的代码就像这样(created_at是时间戳):
$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();
我认为没有区别。
答案 0 :(得分:1)
你不需要介于此之间:
$myDate = new Carbon('2016-01-10');
User::whereDate('created_at', '=', $myDate->format('Y-m-d'))->get();
答案 1 :(得分:0)
你可以使用他的
之类的东西\Illuminate\Database\Query\Builder Line 902
User::whereDate('created_at', '=', new Carbon('2016-01-10'))->get();
没有碳
User::where( DB::raw('DATE(created_at)'), '=', '2016-01-10')->get();
OR
$d = new Carbon('2016-01-10');
User::whereRaw('DATE(created_at) = ?', [$d])->get();