我在我的桌面产品中有这样的字段
--exp_date--
2016-08-02
2016-08-28
2016-08-28
2016-08-23
2016-08-15
2016-08-05
2016-08-20
exp_date
已经在mysql的date
格式
我想select
数据,从今天起,剩下的exp_date
日期不到15
我已经尝试过这样的事了
$dn = date('Y-m-d'); //today date
$query = DB::table('product')->where(DB::raw('datediff(exp_date), $dn') < 15)->get();
但我得到这个错误
Object of class Illuminate\Database\Query\Expression could not be converted to int
怎么解决?
PS: 我使用laravel 4.2并且更喜欢它是由查询构建器或原始查询
试试这段代码
$expDate = Carbon::now()->subDays(15));
Table::whereDate('exp_date', '<',$expDate);
在Laravel Query中,日期差异适用于我。
DB::table('product')->whereRaw('DATEDIFF(exp_date,current_date) < 15')->get();