【问题标题】:Laravel Query Builder - Error for using NOW() and DateFormatLaravel 查询生成器 - 使用 NOW() 和 DateFormat 时出错
【发布时间】:2015-12-24 19:29:06
【问题描述】:

我有一个这样的 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()');

所以,我收到这 2 行的错误-

        DB::raw('concat(DATE_FORMAT(starts_on,"%d %b %Y %h:%i %p), " ", timezone) as starts')

        ->where('starts_on >= NOW()');

错误是 -

谁能帮帮我?

【问题讨论】:

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


    【解决方案1】:

    日期掩码后缺少双引号:

    DB::raw('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')
    

    ->where('starts_on >= NOW()');

    你可以使用:

    whereRaw('starts_on >= NOW()')

    where('starts_on', '>=', new DateTime('today'))

    【讨论】:

      猜你喜欢
      • 2017-03-01
      • 1970-01-01
      • 2021-02-13
      • 2018-07-03
      • 2015-12-13
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      相关资源
      最近更新 更多