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

查看:18
本文介绍了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;
}

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

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