A PHP example to get the range array between two dates:

<?php 
function create_dates_range_array( $start_date, $end_date ) {
    $dates_range_array = array();
 
    $start_date_time = mktime( 1, 0, 0, substr( $start_date, 5, 2 ), substr( $start_date, 8, 2 ), substr( $start_date, 0, 4 ) );
    $end_date_time = mktime( 1, 0, 0, substr( $end_date, 5, 2), substr( $end_date, 8, 2 ), substr( $end_date, 0, 4 ) );
 
    if ( $end_date_time >= $start_date_time ) {
        array_push( $dates_range_array, date( 'Y-m-d', $start_date_time ) );
 
        while ( $end_date_time > $start_date_time  ) {
            $start_date_time += 86400;
 
            array_push( $dates_range_array, date( 'Y-m-d', $start_date_time ) );
        }
    }
 
    return $dates_range_array;
}
 
$start_date = '2013-02-23';
$end_date = '2013-03-11';
 
$dates_range_array = create_dates_range_array( $start_date, $end_date );
 
print_r( $dates_range_array );
?>
Share

Leave a Reply

Info