<?php function add_calendar_months($date_str, $months){ $dt = new DateTime($date_str, new DateTimeZone('UTC')); $day = (int) $dt->format('j'); $dt->modify('first day of this month'); $dt->modify("+{$months} months"); $max_day = (int) $dt->format('t'); $dt->setDate((int) $dt->format('Y'), (int) $dt->format('n'), min($day, $max_day)); return $dt; } $r = add_calendar_months('2026-02-28 23:59:59', 1); echo "RESULT_TIME=" . $r->format('Y-m-d H:i:s') . "\n"; // also show what 'first day of this month' alone does to time: $d2 = new DateTime('2026-02-28 23:59:59', new DateTimeZone('UTC')); $d2->modify('first day of this month'); echo "FIRSTDAYONLY=" . $d2->format('Y-m-d H:i:s') . "\n";
You have javascript disabled. You will not be able to edit any code.