How to combine two dates into a normal human-readable date range

Say you have the following date range:

2010-04-10 - 2010-04-15

As a person, I can write it as April 10 - 15, 2010or something like that. Not sure if there is a certain correct way to write such ranges, but in any case, if you did something like that, how would you do it? I don’t even know where to start ...

I would like to do this so that date ranges can be more compact, easy to read and enjoyable.

+3
source share
2 answers

, , . , , , . , , . , ? , 2005 2007 , 2005-2007 ?

, . , .

+5

, . , .

    $start_date = strtotime('2012-11-01');  
    $end_date = strtotime('2012-11-02');


    if ($end_date != '') {  
        $year1 = date('Y', $start_date);  
        $year2 = date('Y', $end_date);  
        $month1 = date('m', $start_date);  
        $month2 = date('m', $end_date);     

        if ($start_date < $end_date) {  
            if ($year1 != $year2) {  
                $holiday_date = date('F j, Y', $start_date) . ' to ' . date('F j, Y', $end_date);  
            }  
            else {  
                if ($month1 != $month2) {  
                          $holiday_date = date('F j', $start_date) . '&ndash;' . date('F j', $end_date) . ', '. date('Y', $end_date);  
                }  
                else {  
                          $holiday_date = date('F j', $start_date) . '&ndash;' . date('j', $end_date) . ', '. date('Y', $end_date);  
                }  
            }  
        }  
        else {  
                $holiday_date = 'Invalid date range.';  
        }  
    }  
    else {  
            $holiday_date = date('F j, Y', $start_date);  
    }    
    echo $holiday_date;  
+3

Source: https://habr.com/ru/post/1767076/


All Articles