在今天的查询构建器laravel中,datediff <15
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在今天的查询构建器laravel中,datediff <15相关的知识,希望对你有一定的参考价值。
我在我的桌面产品中有这样的字段
--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 IlluminateDatabaseQueryExpression 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();
以上是关于在今天的查询构建器laravel中,datediff <15的主要内容,如果未能解决你的问题,请参考以下文章