gpt4 book ai didi

mysql - Laravel where 子句与 DATEDIFF()

转载 作者:行者123 更新时间:2023-11-29 18:10:29 34 4
gpt4 key购买 nike

我需要获取 DATEDDIFF() >30 和 <60 的所有记录。

我尝试过查询,但它不起作用。

如何获取符合条件的数据。

我的查询是,

 $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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com