@ 2015-04-03T12:09:04Z <?php
$base = new DateTime("2000-03-04 00:00:00 Europe/Berlin");
$date = new DateTime("2016-09-04 00:00:00 Europe/Berlin");
$interval = new DateInterval('P5Y6M1D');
$ret = $date;
$diff = $base->diff($date);
// var_dump($diff);
$iterations = 0;
if ($interval->y || $interval->m || $interval->d) {
$y = $base->format('Y');
$m = $base->format('m');
$d = $base->format('d');
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";
}
if ($interval->d) {
var_dump($diff->d, ($interval->d * $iterations));
$modify = $diff->d - ($interval->d * $iterations);
if ($modify > 0) {
$d += $modify;
$y += $interval->y;
$m += $interval->m;
$iterations++;
echo "set y:{$y}, m:{$m}, d:{$d}, iterations:{$iterations}\n";
} else {
$d += $modify;
}
}
$ret->setDate($y, $m, $d);
}
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;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 set y:2015, m:21, iterations:3
int(0)
float(3)
2016-09-01 00:00:00
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
set y:2015, m:21, iterations:3
int(0)
float(3)
2016-09-01 00:00:00
Output for 4.4.2 - 4.4.9 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Parse error: syntax error, unexpected ':' in /in/5tgPU on line 76
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 , 5.0.0 - 5.0.5 Parse error: parse error, unexpected ':' in /in/5tgPU on line 76
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/5tgPU on line 76
Process exited with code 255 . preferences:dark mode live preview
236.83 ms | 401 KiB | 312 Q