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?
            Asked
            
        
        
            Active
            
        
            Viewed 40 times
        
    0
            
            
        
        Nguyễn Thành Đức
        
- 1
 - 2
 
- 
                    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 Answers
0
            
            
        Here is the sql query that can help you
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
- 
                    There is nothing in the question that says it's database related, but you might be correct. – Andreas Aug 22 '19 at 10:25
 - 
                    
 
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