我正在尝试根据当前日期获取开始日期和结束日期之间的记录。我有正常的SQL工作查询,现在尝试将其转换为雄辩的查询,但是我在某处失败。为此,请帮助我。
基本查询:
SELECT startDate, endDate
FROM YourTable
WHERE '2012-10-25' between startDate and endDate
我尝试过的:
$q = RoundTable::select(['round_start_date','round_end_date'])->whereBetween('2019-10-25', ['round_start_date', 'round_end_date'])->get();
我遇到错误
Column not found: 1054 Unknown column '2019-10-25' in 'where clause' (SQL: select `
round_start_date`, `round_end_date` from `round_table` where `2019-10-25` between round_start_date
and round_end_date`
答案 0 :(得分:3)
将查询更改为:
$q = RoundTable::select(['round_start_date','round_end_date'])
->whereRaw('? between round_start_date and round_end_date', ['2019-10-25'])
->get();