Php 具有30天前条件的Laravel 4查询

Php 具有30天前条件的Laravel 4查询,php,mysql,laravel,laravel-4,Php,Mysql,Laravel,Laravel 4,我不明白哪里出了问题。当我加上这个 其中('units.solddate','>=','DATE_SUB(CURDATE(),INTERVAL 30 DAY)' where子句和我的结果为空。我在phpMyadmin中进行了尝试,它确实返回了结果 $query= (tables) ->select(DB::raw('SUM(units.price) as price, DATE(units.solddate) as date, DAY(units.solddate) as

我不明白哪里出了问题。当我加上这个

其中('units.solddate','>=','DATE_SUB(CURDATE(),INTERVAL 30 DAY)'

where子句和我的结果为空。我在phpMyadmin中进行了尝试,它确实返回了结果

$query= (tables)
        ->select(DB::raw('SUM(units.price) as price, DATE(units.solddate) as date, DAY(units.solddate) as day'))
        ->where('units.solddate','>=','DATE_SUB(CURDATE(), INTERVAL 30 DAY)')
        ->where('units.solddate','<=','NOW()')
        ->groupBy('date')
        ->get();
$query=(表)
->选择(DB::raw('SUM(units.price)作为价格,DATE(units.solddate)作为日期,DAY(units.solddate)作为日期'))
->其中('units.solddate','>=','DATE_SUB(CURDATE(),INTERVAL 30 DAY)'

->其中('units.solddate','约束不起作用的原因是,Elount从字面上获取您比较的值,在需要时转义它,然后在查询中使用。如果

->where('units.solddate','<=','NOW()')

->where('units.solddate','where('units.solddate','If
solddate
是日期时间,那么使用
now()
而不是
CURDATE()
woww谢谢!我不知道会将now()视为字符串。谢谢:D
... WHERE units.solddate <= 'NOW()'
->where('units.solddate','>=',DB::raw('DATE_SUB(CURDATE(), INTERVAL 30 DAY)'))
->where('units.solddate','<=',DB::raw('NOW()'))