<?php
function add_one_month($date) {
// find the next month
$nextmonth = mktime(0, 0, 0, date("n", $date) + 1, 1, date("Y", $date));
// limit the day number according to the month
$day = min(date("t", $nextmonth), date("j", $date));
// combine into desired date
return mktime(0, 0, 0, date("n", $nextmonth), $day, date("Y", $nextmonth));
}
for ($d = 20; $d <= 31; $d++) {
$date = mktime(0, 0, 0, 1, $d, 2017);
$normal = date("Y-m-d", strtotime("+1 month", $date));
$addonemonth = date("Y-m-d", add_one_month($date));
printf("2017-01-%02d: +1 month = %s add_one_month = %s\n", $d, $normal, $addonemonth);
}
preferences:
25.35 ms | 408 KiB | 5 Q