[英]Laravel Carbon subtract days from current date
I am trying to extract objects from Model "Users" whose created_at
date has been more than 30 days from today .我正在尝试从 Model "Users" 中提取对象,其
created_at
日期从今天开始已经超过 30 天。
Carbon::now() ==> I want as ==> Carbon::now() - 30days Carbon::now() ==> 我想要 ==> Carbon::now() - 30 天
$users = Users::where('status_id', 'active')
->where( 'created_at', '<', Carbon::now())
->get();
How can this be achieved?如何做到这一点?
As with strtotime or DateTime, any (relative) date expressions can also be used with carbon::parse
.与 strtotime 或 DateTime 一样,任何(相对)日期表达式也可以与
carbon::parse
一起使用。
$users = Users::where('status_id', 'active')
->where( 'created_at', '>', Carbon::parse('Now -30 days'))
->get();
Alternatively for 'Now -30 Days', expressions '-30days' or '-720 hours' are also possible.或者,对于“现在 -30 天”,表达式“-30 天”或“-720 小时”也是可能的。
'Now -30 Days' takes into account the current time. “现在 -30 天”考虑了当前时间。 If you need a time 00:00, use 'Today -30 Days'.
如果您需要时间 00:00,请使用“今天 -30 天”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.