3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $base = new DateTime("2000-03-04 00:00:00 Europe/Berlin"); $date = new DateTime("2016-09-07 00:00:00 Europe/Berlin"); $interval = new DateInterval('P5Y6M1D'); $ret = $date; $diff = $base->diff($date); // var_dump($diff); $iterations = 0; $y = $base->format('Y'); $m = $base->format('m'); $d = $base->format('d'); $h = $base->format('G'); $i = $base->format('i'); $s = $base->format('s'); if ($interval->y || $interval->m) { $monthDiff = $diff->y * 12 + $diff->m; $monthInterval = $interval->y * 12 + $interval->m; $iterations = ceil($monthDiff / $monthInterval); $y = $base->format('Y') + ($interval->y * $iterations); $m = $base->format('m') + ($interval->m * $iterations); echo "set y:{$y}, m:{$m}, iterations:{$iterations}\n"; } $modify = $diff->d - ($interval->d * $iterations); if ($modify > 0) { $y += $interval->y; $m += $interval->m; $iterations++; } $d += $interval->d * $iterations; echo "set y:{$y}, m:{$m}, d:{$d}, iterations:{$iterations}\n"; $modify = $diff->h - ($interval->h * $iterations); if ($modify > 0) { $y += $interval->y; $m += $interval->m; $d += $interval->d; $iterations++; } $h += $interval->h * $iterations; echo "set y:{$y}, m:{$m}, d:{$d}, h:{$h}, iterations:{$iterations}\n"; $ret->setDate($y, $m, $d); $ret->setTime($h, $i, $s); echo $ret->format("Y-m-d H:i:s") . "\n"; exit; if ($interval->y) { $y = $diff->y / $interval->y; if ($y) { $intervals = $y / $interval->y; $m = $interval->m * $intervals; $y -= floor($m / 12); $m -= floor($m / 12) * 12; $ret->setDate( $base->format('Y') + $y, $base->format('m') + $m, $base->format('d') ); /* $ret->setTime( $base->format('G') + ($interval->h * $intervals), $base->format('i') + ($interval->i * $intervals), $base->format('s') + ($interval->s * $intervals) ); */ } } var_dump($ret); exit; $intervalMonths = $interval->m ?: 12; $m = ceil($diff->m / $intervalMonths) * $intervalMonths; if ($interval->d) { $d = ceil($diff->d / $interval->d) * $interval->d; } else { $d = 0; } $intervalHours = $interval->h ?: 24; $intervalMinutes = $interval->i ?: 60; $intervalSeconds = $interval->s ?: 60; $h = ceil($diff->h / $intervalHours) * $intervalHours; $i = ($h) ? $interval->i : ceil($diff->i / $intervalMinutes) * $intervalMinutes; $s = ($h || $i) ? $interval->s : ceil($diff->s / $intervalSeconds) * $intervalSeconds; if ($interval->d) { $d = ceil($diff->d / $interval->d) * $interval->d; } if ($interval->m) { $m = ceil($diff->m / $interval->m) * $interval->m; } if ($interval->y) { $y = ceil($diff->y / $interval->y) * $interval->y; } $s += $base->format('s'); $i += $base->format('i'); $h += $base->format('G'); $d += $base->format('d'); $m += $base->format('m'); $y += $base->format('Y'); $ret->setTime($h, $i, $s); //$ret->setDate($y, $m, $d); return $ret;
based on aXrNN

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page