如何比较 laravel 中的两个日期

how to compare two date in laravel

I'm having a hard time in comparing two date in laravel, I try this code below in mysql and it works well but when I transfer it on laravel it doesn't work

SELECT * FROM `holiday` WHERE date_format(holiday.date,'%m-%d') = date_format('2017-05-15','%m-%d')

here is my code in laravel

public function getHoliday(){
 $date = '2017-05-15';

         $data = DB::table('holiday')
         ->select(
            'holiday.id'
            )
        ->whereRaw("date_format(holiday.date, '%m-%d') "=" date_format($date, '%m-%d')")

        ->first();



        return $data;

    }

I do hope you could help me with my code, I just want to compare day and month of two date

尝试更改此行:

->whereRaw("date_format(holiday.date, '%m-%d') "=" date_format($date, '%m-%d')")

至此

 ->where(date_format(holiday.date, '%m-%d') , date_format($date, '%m-%d'))

编辑。

尝试改用这个约会助手

          ->whereDay('date', '=', date('d'))
          ->whereMonth('date', '=', date('m'))
          ->first();
$data = DB::table('holiday')
    ->select([
        'holiday.id',
        'holiday.date',
    ])
    ->whereRaw("date_format(holiday.date, '%m-%d') = date_format('$date', '%m-%d')")
    ->first();