In this tutorial I will teach you how to get the weeks between two dates in PHP 5 and above.
// Start date $start = new DateTime('2016-03-01 00:00:00'); // End date $end = new DateTime('2016-05-21 00:00:00'); // Get the difference in days between the two dates $interval = $start->diff($end)->days; // Divide by 7 to get the total weeks. $weeks = floor($interval /7); echo $weeks;
That’s it. A very simple but useful code to get the weeks between two dates.