我试图找出一个时间段是否在一个时间段内。我有我的引用时间段和我的比较时间段。 我举个例子:
- 时间段 A(引用)从 2014 年 1 月 1 日到 2014 年 2 月 1 日 (tt.mm.yyyy)。
- 时间段 B(比较)从 2014 年 4 月 1 日到 2014 年 5 月 1 日。
=> 这完全没问题。
- 时间段 C(引用)为 2014 年 1 月 1 日至 2014 年 3 月 1 日
- 时间段 D(比较)从 2014 年 2 月 1 日到 2014 年 5 月 1 日。
=> 不行,因为 D 在 C 中。
希望你能得到我想要的。我尝试使用 serval < = > if 操作,但这开始变得巨大且缓慢。也许有更快的方法来做到这一点。
还有,MySQL 能做这样的事情吗?
最佳答案
你可以用php时间戳来尝试这个
$reference_start_date = "1.1.2014";
$reference_end_date = "1.2.2014";
$comparative_start_date = "1.4.2014";
$comparative_end_date = "1.5.2014 ";
$reference_start_time = strtotime(str_replace(".", "-", $reference_start_date);
$reference_end_time = strtotime(str_replace(".", "-", $reference_end_date);
$comparative_start_time = strtotime(str_replace(".", "-", $comparative_start_date);
$comparative_end_time = strtotime(str_replace(".", "-", $comparative_end_date);
if($comparative_start_time>$reference_start_time && $comparative_start_time<$reference_end_time)
{
echo "Not OK";
}
else if($comparative_end_time>$reference_start_time && $comparative_end_time<$reference_end_time)
{
echo "Not OK";
}
else if($comparative_start_time<$reference_start_time && $comparative_end_time>$reference_end_time)
{
echo "Not OK";
}
else
{
echo "OK";
}
关于php - 时间段中的时间段 (PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24839380/