Search code examples
phpsqllaraveldatecomparison

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


Solution

  • you can use whereDate since you have date column in database

    $dateUp= Jadwal::whereDate('pembibitan', ">" ,$today)->get();
    

    As per official documention

    The whereDate method may be used to compare a column's value against a date