Laravel Carbon查看日期是否过去 [英] Laravel Carbon See if date is in the past

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

问题描述

对此我感到很困惑,也许我没有看到它的简单之处.如果我想看看日期是否是今天的过去,我应该可以执行以下操作吗?

I am very confused by this, maybe its something simple I am not seeing. If I want to see if a date is in the past of today I should be able to do something like this?

if( $league->date_start <= Carbon::now() ){
    $join  = false;
    $message = 'Sorry, the league has already started';
}

如果我丢弃日期

$league->date_start = 2017-07-31 00:00:00
Carbon::now() = 2017-11-01 16:29:27

$league->date_start是受保护的日期,因此它是碳实例

$league->date_start is a protected date so its a carbon instance

但是这不起作用,如果我将其切换到$league->date_start >= Carbon::now()则它起作用并且不会让我加入.我知道联盟"的开始日期是过去的日期,所以它不应该是$league->date_start <= Carbon::now() ?????

But this doesnt work, if I switch it to $league->date_start >= Carbon::now() it works and wont let me join. I know the "league" start date is in the past so shouldnt it be $league->date_start <= Carbon::now()?????

推荐答案

有内置的Carbon方法isPast,因此您可以使用:

There's built-in Carbon method isPast so you can use:

$league->date_start->isPast()

确定日期是否过去

这篇关于Laravel Carbon查看日期是否过去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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