如何搜索created_at
日期,忽略一天中的时间?
我现在这样做,但感觉有点像黑客:
$searchDate = strtotime($search);
if($searchDate !== false) {
$q->orWhere(DB::raw('DATE(`created_at`)'), Carbon::createFromTimestamp($searchDate)->toDateString());
}
答案 0 :(得分:2)
有一种方法可以做到:
$search_date = Carbon::createFromTimestamp($searchDate)->toDateString();
$q->where('created_at','LIKE', $search_date . '%')->get();
或者你可以这样写,
$search_date = Carbon::createFromTimestamp($searchDate)->toDateString();
$q->orWhereRaw('DATE(created_at) = ?'), array($search_date));