php问题...如何检查两个值之间是否有东西?

2022-01-25 00:00:00 date compare php

我知道我在这里遗漏了一些简单的东西...我一直在尝试不同的运算符,但无法解决这个问题...

I know I'm missing something easy here... I've been trying different operators, but haven't been able to figure this out...

如何检查当前日期是否在另外两个日期之间?

How do I go about checking to see if the current date is between two other dates?

那么,如果我的起始日期为 2010 年 2 月 2 日,截止日期为 2010 年 2 月 10 日,如果当前日期(2010 年 2 月 4 日)介于这两个日期之间,我如何返回 TRUE?

So, if I have a from date of 2/2/2010 and a to date of 2/10/2010, how can I return TRUE if the current date (2/4/2010) falls between those two dates?

推荐答案

要进行这样的比较,您需要进行单独的比较.如果 $d 是您要比较的日期,$d1 是较早的日期,$d2 是较晚的日期,则类似于:

To do a comparison like this you need to do separate comparisons. If $d is the date you want to compare, $d1 is the earlier date, and $d2 is the later date, it would be something like:

if ((strtotime($d) > strtotime($d1)) and (strtotime($d) < strtotime($d2))) {
    return true;
} else {
    return false;
}

相关文章