Reputation: 1115
Suppose I have a date specific as 2016-11-14
.
Also I have another date (starting) 02-14-2017
and ending 02-30-2017
I want to count the months that has passed is the date 2016-11-14
until the set of Range date.
I tried searching but I cant find a link on how to find months that has passed from a date to set of range date
Upvotes: 2
Views: 610
Reputation: 219814
DateTime()
makes doing date math easy:
$datetime1 = new DateTime('2016-12-01');
$datetime2 = new DateTime('2017-02-01');
$interval = $datetime2->diff($datetime1);
echo (($interval->format('%y') * 12) + $interval->format('%m'));
Upvotes: 4