php问题...如何检查某事是否在两个值之间? [英] php question... how to check if something is between two values?

查看:829
本文介绍了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日, to date of 2/10/2010,如果当前日期(2/4/2010)落在这两个日期之间,如何返回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;
}

这篇关于php问题...如何检查某事是否在两个值之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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