php php日期小于另一个日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17329281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:41:30  来源:igfitidea点击:

php date less than another date

phpdatecomparestrtotime

提问by CQM

given this kind of date object date("m/d/Y", strtotime($numerical." ".$day." of ".date("F")))

给定这种日期对象 date("m/d/Y", strtotime($numerical." ".$day." of ".date("F")))

where it may give a mm/dd/yyyy day that is the "first Monday of August", for instance

例如,它可能会给出一个 mm/dd/yyyy 天,即“八月的第一个星期一”

how can I decide if this date is greater than, less than, or equal to today's date?

我如何确定这个日期是大于、小于还是等于今天的日期?

I need a now()method that works in this format and can be compared between date objects

我需要一种now()以这种格式工作并且可以在日期对象之间进行比较的方法

I haven't tried date() < date() , yet. But I don't think that will work

我还没有尝试过 date() < date() 。但我认为这行不通

any insight appreciated

任何见解表示赞赏

回答by bwoebi

Compare the timestamps:

比较时间戳:

if (strtotime($numerical." ".$day." of ".date("F")) < time()) {
    // older
} else {
    // newer
}

This is possible as strtotime()returns the seconds since 1.1.1970 and time()too. And in PHP you can easily compare integers...

这是可能的,因为strtotime()返回自 1.1.1970 以来的秒数time()。在 PHP 中,您可以轻松比较整数...