John Davidson

php - comparing date from db on laravel use sql


im trying to compare date from db on laravel but the comparison is failed probably wrong way to compare

$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]);

the output end up with foreach display all data that exist on db

My Answer:
$events = Event::where('date', '>=', $today)->get();

This code snippet should work for comparing dates from the database in Laravel. It retrieves all events where the date is greater than or equal to today's date. Make sure to adjust the date format in the 'date' column of your database table to match 'Y-m-d' format for accurate comparison.

Rate this post

3 of 5 based on 4427 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us