PHP time split problem?

known :
$beginDate = "2018-07";
$endDate = "2018-11";

how to implement :

in code

for example, this month is November, then

2018-11 this month
2018-10 exceeds January
2018-09 exceeds February
2018-08 exceeds March
2018-07 exceeds April

the time after July defaults to "beyond April"

Php
Oct.17,2021

can be implemented using the DateTime class, and DateTime is also an officially recommended method for time calculation

$beginDate = '2018-07;
$endDate =' 2018-02;

$start = new DateTime ($beginDate);
$end = new DateTime ($endDate);

echo sprintf ('past% d months', $end- > diff ($start)-> m > 4? 4: $end- > diff ($start)-> m);


date('m', strtotime('2018-07'))

Why does such a simple logic ask? Instead of trying to write

yourself.
Menu