Laravel查询生成器 - 错误使用NOW()和日期格式
问题描述:
我有一个MySQL表像这个 -Laravel查询生成器 - 错误使用NOW()和日期格式
而且Laravel像这 -
$baseQuery = DB::table('webinars')
->select(
'id',
'title',
'description',
'hosts',
DB::raw('concat(DATE_FORMAT(starts_on,"%d %b %Y %h:%i %p), " ", timezone) as starts'),
'duration',
'created_at'
)
->where('user_id', '=', $user_ID)
->where('starts_on >= NOW()');
所以一个查询生成器,我收到错误此2线 -
DB::raw('concat(DATE_FORMAT(starts_on,"%d %b %Y %h:%i %p), " ", timezone) as starts')
而且
->where('starts_on >= NOW()');
错误是 -
谁能帮助我吗?
答
你缺少日期面膜后一个双引号:
DB ::原料('CONCAT(DATE_FORMAT(starts_on, “%d%B%Y%H:%I%P)”,“ , 时区),其开始 ')
应该是:
DB::raw('concat(DATE_FORMAT(starts_on, "%d %b %Y %h:%i %p"), " ", timezone) as starts')
- >其中(' starts_on> = NOW()');
你可以使用:
whereRaw('starts_on >= NOW()')
或
where('starts_on', '>=', new DateTime('today'))
我undrstand,谢谢 –