Something to aware with, if you are using this method to plus 1 month to a date,
make sure your initial date is not the last day of the month.
For example: if the initial date is 2018-03-31,
when the system plus 1 month, the system will return 2018-04-31, when it is not a valid date,
then it will change it to 2018-05-01.
Advice is to use the initial date with the day as 1.
Sample Code A:
$selectdate = '2018-03-31';
echo "First date is 2018-03-31"."<br>";
for ($x=0; $x<=5; $x++){
$selectdate = date("Y-m-d",strtotime($selectdate.' +1 months'));
echo $selectdate.' <br>';
}
Result for A:
First date is 2018-03-31
2018-05-01
2018-06-01
2018-07-01
2018-08-01
2018-09-01
2018-10-01
Sample Code B:
$selectdate = '2018-03-01';
echo "First date is 2018-03-01"."<br>";
for ($x=0; $x<=5; $x++){
$selectdate = date("Y-m-d",strtotime($selectdate.' +1 months'));
echo $selectdate.' <br>';
}
Result for B:
First date is 2018-03-01
2018-04-01
2018-05-01
2018-06-01
2018-07-01
2018-08-01
2018-09-01