Laravel Carbon从当前日期减去天数 [英] Laravel Carbon subtract days from current date

查看:2024
本文介绍了Laravel Carbon从当前日期减去天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从其created_at日期已超过今天 30天的用户"模型中提取对象.

I am trying to extract objects from Model "Users" whose created_at date has been more than 30 days from today.

Carbon :: now()==>我要==> Carbon :: now()-30天

Carbon::now() ==> I want as ==> Carbon::now() - 30days

$users = Users::where('status_id', 'active')
               ->where( 'created_at', '<', Carbon::now())
               ->get();

这如何实现?

推荐答案

使用 subDays() 方法:

$users = Users::where('status_id', 'active')
           ->where( 'created_at', '>', Carbon::now()->subDays(30))
           ->get();

这篇关于Laravel Carbon从当前日期减去天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆