我的表格产品中有这样的字段
--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
格式
我想选择
从今天起剩余exp_date
小于15的数据
我已经尝试过这样的事情了
$dn = date('Y-m-d'); //today date
$query = DB::table('product')->where(DB::raw('datediff(exp_date), $dn') < 15)->get();
但我收到此错误
Illuminate\Database\Query\Expression 类的对象无法转换为 int
如何解决?
ps:
我使用的是 laravel 4.2 并且更喜欢通过查询构建器或原始查询
最佳答案
试试这段代码
$expDate = Carbon::now()->subDays(15));
Table::whereDate('exp_date', '<',$expDate);
关于laravel - 在查询生成器 laravel 中,datediff < 15 从今天开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39057339/