mysql - Laravel 查询生成器 - 使用 NOW() 和 DateFormat 时出错

标签 mysql laravel laravel-4 laravel-5 query-builder

我有一个像这样的 MySQL 表-

enter image description here

还有像这样的 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()');

错误是-

enter image description here

谁能帮帮我?

最佳答案

您在日期掩码后缺少双引号:

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/

相关文章:

php - Laravel 中的 setPasswordAttribute

mysql - 更新 mysql 表中新字段的信息?

php - MySQL : Order by and Group By combining not giving the latest record

mysql - (My)SQL 迭代地使用一个表中的数据填充另一个表/从列表中选择

laravel - Webpack 已使用与使用 Vue Js 的 Laravel 7 中的 API 模式不匹配的配置对象进行初始化

php - 如何在数据库的同一列中保存多个行输入?

php - Laravel:laravel 可翻译插件

mysql - Javascript 自动完成列出 MySQL 结果

arrays - "Array to string conversion"错误 Laravel - 尝试将数组保存到数据库

php - Laravel:Select2 选项值