检查日期时间是否发生在最后 7 分钟内

Check if datetime happened in the last 7 minutes

我正在使用 PHP 7.4.1Laravel Framework 6.20.12 以及 carbon 库。

我想检查某个日期是否发生在 7 分钟之前。

我试过了:

        $now = Carbon::now();
        $lastPosting = $now->addMinutes(7);



        if($now->gt($lastPosting)) {
            return true;
        } else {
            return false;
        }

上述代码的问题在于它将所有过去的日期设置为 true。

对我做错了什么有什么建议吗?

感谢您的回复!

我对 Carbon 不太熟悉,但这是我的方法:使用 between():

if($lastPosting->between( $now->subMinutes(7), $now){
    //anything in between the last 7 minutes
}
else{
    //whatever else
}