我只是想改变这个MySql查询在Laravel查询生成器:
SELECT * FROM domain_reg_infos WHERE d_expiryDate BETWEEN NOW() AND NOW() + INTERVAL 1 MONTH
我已经搜索过了,但没有找到任何解决方案。请给我一个正确的解决方案。
提前感谢。
试试这个:
$now = date('Y-m-d H:i:s'); //get today's date
$newdate = date('Y-m-d H:i:s', strtotime ( '+1 month' , strtotime ( $now ) ) ); //add 1 month to $now
$domain_reg_infos = Domain_Reg_Info::whereBetween('expiryDate', array($now, $newdate))->get();
我想你可以先设置当前日期并添加1个月。然后在您的查询中使用它,如:
$current_time = strtotime("2010.12.11");
$one_month_interval = date("Y-m-d", strtotime("+1 month", $current_time));
,
$result = ModelClass::
where('d_expiryDate ','>=',$current_time)
->where('d_expiryDate ','<=',$one_month_interval )
->get();
return $result ;
这很简单,试试那个代码。
DB::table('domain_reg_infos')
->whereRaw('d_expiryDate between NOW() and NOW() + INTERVAL 1 MONTH')
->get();