我有一个像这样的 MySQL 表-
还有像这样的 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()');
所以,我收到了这两行的错误-
DB::raw('concat(DATE_FORMAT(starts_on,"%d %b %Y %h:%i %p), " ", timezone) as starts')
和
->where('starts_on >= NOW()');
错误是-
谁能帮帮我?
最佳答案
您在日期掩码后缺少双引号:
DB::raw('concat(DATE_FORMAT(starts_on, "%d %b %Y %h:%i %p), " ", timezone) as starts')
应该是:
DB::raw('concat(DATE_FORMAT(starts_on, "%d %b %Y %h:%i %p"), " ", timezone) as starts')
->where('starts_on >= NOW()');
你可以使用:
whereRaw('starts_on >= NOW()')
或
where('starts_on', '>=', new DateTime('today'))
关于mysql - Laravel 查询生成器 - 使用 NOW() 和 DateFormat 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32808027/