Skip to content

Instantly share code, notes, and snippets.

@leevigraham
Created October 19, 2013 23:08
Show Gist options
  • Save leevigraham/7062681 to your computer and use it in GitHub Desktop.
Save leevigraham/7062681 to your computer and use it in GitHub Desktop.
Print out the last day of the month with an interval optionally showing the end date.
<?php
$includeEndTime = true;
$interval = \DateInterval::createFromDateString('last day of next month');
$start = new \DateTime("last day of January 2000");
$end = new \DateTime("last day of December 2001");
if(true === $includeEndTime) {
$end->add($interval);
}
$datePeriod = new \DatePeriod($start, $interval, $end);
foreach($datePeriod as $date) {
var_dump($date);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment