【问题标题】:How to check if the date is in the past in PHP? [duplicate]如何在PHP中检查日期是否过去? [复制]
【发布时间】:2016-01-21 12:34:41
【问题描述】:

我的日期格式是:2016 年 1 月 21 日 我想检查它是否在过去或不在 PHP 中。 我该怎么做?

【问题讨论】:

    标签: php


    【解决方案1】:

    使用strtotime()

    if(strtotime($date)<strtotime("today")){
        echo "past";
    } elseif(strtotime($date)==strtotime("today")){
        echo "today";
    } else {
        echo "future";
    }
    

    【讨论】:

    • 它有效。非常感谢。
    • time()不是比strtotime("today")简单吗?
    • @TRiG, time() 会给出当前日期和时间,但strtotime('Jan-21-2016') 会给出当天午夜的日期。这将导致 today 案例出现问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    相关资源
    最近更新 更多