比较 laravel 上数据库的日期使用 sql
comparing date from db on laravel use sql
我正在尝试比较 laravel 上数据库的日期,但比较失败可能是错误的比较方式
$today = date("Y-m-d");
$dateUp= Jadwal::where('pembibitan', ">" ,strtotime($today))->get();;
$date= Jadwal::where('pembibitan', '<' ,strtotime($today))->get();;
return view('dashboard',['date'=>$date ,'dateUp'=>$dateUp, 'today'=>$today]);
输出以 foreach 结束,显示 db 上存在的所有数据
你可以使用 whereDate
因为你在数据库中有日期列
$dateUp= Jadwal::whereDate('pembibitan', ">" ,$today)->get();
根据官方文档
The whereDate method may be used to compare a column's value against a
date
我正在尝试比较 laravel 上数据库的日期,但比较失败可能是错误的比较方式
$today = date("Y-m-d");
$dateUp= Jadwal::where('pembibitan', ">" ,strtotime($today))->get();;
$date= Jadwal::where('pembibitan', '<' ,strtotime($today))->get();;
return view('dashboard',['date'=>$date ,'dateUp'=>$dateUp, 'today'=>$today]);
输出以 foreach 结束,显示 db 上存在的所有数据
你可以使用 whereDate
因为你在数据库中有日期列
$dateUp= Jadwal::whereDate('pembibitan', ">" ,$today)->get();
根据官方文档
The whereDate method may be used to compare a column's value against a date