How to calculate whether two time periods intersect in PHP

小云云
Release: 2023-03-22 06:38:01
Original
2348 people have browsed it

This article mainly shares with you how PHP calculates whether two time periods overlap. It is mainly shared with you in the form of code. I hope it can help you.

/**
 * PHP计算两个时间段是否有交集(边界重叠不算)
 *
 * @param string $beginTime1 开始时间1
 * @param string $endTime1 结束时间1
 * @param string $beginTime2 开始时间2
 * @param string $endTime2 结束时间2
 * @return bool
 */function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') {
    $status = $beginTime2 - $beginTime1;    if ($status > 0) {        $status2 = $beginTime2 - $endTime1;        if ($status2 >= 0) {            return false;
        } else {            return true;
        }
    } else {        $status2 = $endTime2 - $beginTime1;        if ($status2 > 0) {            return true;
        } else {            return false;
        }
    }
}
Copy after login
Copy after login
/**
 * PHP计算两个时间段是否有交集(边界重叠不算)
 *
 * @param string $beginTime1 开始时间1
 * @param string $endTime1 结束时间1
 * @param string $beginTime2 开始时间2
 * @param string $endTime2 结束时间2
 * @return bool
 */function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') {
    $status = $beginTime2 - $beginTime1;    if ($status > 0) {        $status2 = $beginTime2 - $endTime1;        if ($status2 >= 0) {            return false;
        } else {            return true;
        }
    } else {        $status2 = $endTime2 - $beginTime1;        if ($status2 > 0) {            return true;
        } else {            return false;
        }
    }
}
Copy after login
Copy after login

Related recommendations:

php function to compare whether there is an intersection between time periods

The above is the detailed content of How to calculate whether two time periods intersect in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!