Laravel 7:获取两个日期之间的行,其中列为datetime

tct7dpnv  于 2023-11-20  发布在  其他
关注(0)|答案(1)|浏览(72)

我在构建一个有说服力的查询时遇到了麻烦,我可以在其中重新创建这个sql命令:date_created列是datetime。

SELECT * FROM covidchecklist cc 
LEFT JOIN patient_appointment pa ON cc.appointment_id = pa.appointment_id 
LEFT JOIN users pat ON pa.user_id = pat.id 
WHERE DATE_FORMAT(cc.date_created,'%Y-%m-%d') BETWEEN '2021-01-27' AND '2021-01-27'

字符串
我现在所拥有的:

CovidChecklist::leftJoin('patient_appointment', 'covidchecklist.appointment_id', '=', 'patient_appointment.appointment_id')
    ->leftJoin('users as patient', 'patient_appointment.user_id', '=', 'patient.id')
    ->whereRaw(' DATE_FORMAT(covidchecklist.date_created,"%Y-%m-%d") BETWEEN '.'$this->date_from'.' AND '.'$this->date_to'.' ')
    ->select(
        *select stuff*
     )
    ->get();


我使用whereRaw,因为我不能让它工作:

->whereBetween('covidchecklist.date_created', [$this->date_from, $this->date_to])

s4n0splo

s4n0splo1#

试试这个,伙计

->whereBetween(\DB::raw('DATE_FORMAT(covidchecklist.date_created,"%Y-%m-%d")'), [$this->date_from, $this->date_to])

字符串

相关问题