2015-09-27 86 views
1

我有一個MySQL表像這個 -Laravel查詢生成器 - 錯誤使用NOW()和日期格式

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()'); 

所以一個查詢生成器,我收到錯誤此2線 -

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

而且

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

錯誤是 -

enter image description here

誰能幫助我嗎?

回答

1

你缺少日期面膜後一個雙引號:

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'))

+0

我undrstand,謝謝 –