0

So I have the first date range like this: 03/07/2019 - 06/08/2019.
And I have another second date range like this: 30/07/2019 - 01/08/2019.
How can I check if the second date range belongs to the first date range in PHP?

  • Update: Ok have got the answer: https://www.daniweb.com/programming/web-development/threads/493894/check-whether-one-date-range-is-between-another-date-range – Nguyễn Thành Đức Aug 22 '19 at 10:34

2 Answers2

0

Here is the sql query that can help you

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
0

Firstly, you need to convert date from d/m/y to y-m-d ( you can take reference from PHP convert date format dd/mm/yyyy => yyyy-mm-dd ) and then can use below code as:

$firstStartDate = strtotime('2019-07-03');
$firstEndDate = strtotime('2019-08-06');
$secondstartDate = strtotime('2019-07-30');
$secondEndDate = strtotime('2019-08-01');

if (($secondstartDate >= $firstStartDate && $secondstartDate <= $firstEndDate) && ($secondEndDate >= $firstStartDate && $secondEndDate <= $firstEndDate)) {
    echo 'inside range';
}

Hope it helps you!!

Rohit Mittal
  • 2,064
  • 2
  • 8
  • 18