- end: documentation ( source)
- str_pad: documentation ( source)
- iterator_to_array: documentation ( source)
<?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');