I am trying to extract objects from Model "Users" whose created_at date has been more than 30 days from today.
我试图从模型“用户”中提取对象,其创建日期已超过30天。
Carbon::now() ==> I want as ==> Carbon::now() - 30days
Carbon :: now()==>我想要==> Carbon :: now() - 30days
$users = Users::where('status_id', 'active')
->where( 'created_at', '<', Carbon::now())
->get();
How can this be achieved ?
怎么能实现这一目标?
2 个解决方案
#1
37
Use subDays()
method:
使用subDays()方法:
$users = Users::where('status_id', 'active')
->where( 'created_at', '>', Carbon::now()->subDays(30))
->get();
#2
0
You can always use strtotime to minus the number of days from the current date:
您始终可以使用strtotime减去当前日期的天数:
$users = Users::where('status_id', 'active')
->where( 'created_at', '>', date('Y-m-d', strtotime("-30 days"))
->get();
#1
37
Use subDays()
method:
使用subDays()方法:
$users = Users::where('status_id', 'active')
->where( 'created_at', '>', Carbon::now()->subDays(30))
->get();
#2
0
You can always use strtotime to minus the number of days from the current date:
您始终可以使用strtotime减去当前日期的天数:
$users = Users::where('status_id', 'active')
->where( 'created_at', '>', date('Y-m-d', strtotime("-30 days"))
->get();