我需要获取所有DATEDDIFF()> 30和
我已经尝试过查询,但无法正常工作。
我如何获取符合条件的数据。
我的查询是
$cur_date=Carbon::now();
$data=DB::table('mailbox_log as ml')
->leftjoin('registration as r','ml.reg_id','=','r.id')
->leftjoin('company as cmp','r.sociale_id','=','cmp.id')
->select('ml.*','r.id','r.g_id','r.num','cmp.name')
->where(DB::raw('DATEDIFF(ml.sent_pst_date, "%Y-%m-%d")'),$cur_date->format('Y-m-d'),'>','30')
->where(DB::raw('DATEDIFF(ml.sent_pst_date, "%Y-%m-%d")'),$cur_date->format('Y-m-d'),'<','60')
->get()->toArray();
最佳答案
尝试使用Carbon addDays()
$start_date = (Carbon::now())->addDays(30);
$end_date = $start_date->addDays(30);
$data=DB::table('mailbox_log as ml')
->leftjoin('registration as r','ml.reg_id','=','r.id')
->leftjoin('company as cmp','r.sociale_id','=','cmp.id')
->select('ml.*','r.id','r.g_id','r.num','cmp.name')
->where('ml.sent_pst_date','>',$start_date)
->where('ml.sent_pst_date','<',$end_date)
->get()->toArray();
关于mysql - Laravel where子句与DATEDIFF(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47452128/