3v4l.org

run code in 300+ PHP versions simultaneously
<?php function printLastDateInPeriod($startDate, $endDate) { $period = iterator_to_array(new DatePeriod( new DateTime($startDate), new DateInterval('P1D'), new DateTime($endDate) )); echo $startDate->format('Y-m-d H:i:s') . PHP_EOL; echo str_pad("$startDate <-> $endDate: ", 30).end($period)->format('Y-m-d').PHP_EOL; } printLastDateInPeriod('-1 week', 'now'); printLastDateInPeriod('-1 week', 'today'); printLastDateInPeriod('2014-11-10', 'now'); printLastDateInPeriod('2014-11-10', 'today');

preferences:
47.22 ms | 402 KiB | 5 Q