Online Forum To Support Coders With Technical Assistance - Read Write Execute

How to get months name and month days between two differente dates?

Ankit Agrawal
Ankit Agrawal
Published on December 25, 2015 · 1 min read

Please try it.

$start_date  = '2015-11-15';
$end_date  = '2015-12-25';
$result = array();
$start_time   = strtotime($start_date);
$end_time   = date('m-Y', strtotime($end_date));

do {
    $month_year = date('m-Y', $start_time);
    $days = date('t', $start_time);

    $result[] = [
        'month_year' => $month_year,
        'days' => $days,
    ];

    $start_time = strtotime('+1 month', $start_time);
} while ($month_year != $end_time);
Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article Limit word count in word press content Next Article → How to make table responsive