Skip to content

Instantly share code, notes, and snippets.

@sglessard
Last active December 11, 2015 12:29
Show Gist options
  • Save sglessard/4601445 to your computer and use it in GitHub Desktop.
Save sglessard/4601445 to your computer and use it in GitHub Desktop.
SGLFLTS - DateTime : tomorrow and yesterday (symfony2)
// string input ($date = '2013-01-01';)
$day = \DateTime::createFromFormat('Y-m-d', $date);
$date_errors = \DateTime::getLastErrors();
if ($date_errors['warning_count'] + $date_errors['error_count'] > 0) {
throw $this->createNotFoundException('Input date does not exist.');
}
$next_day = clone $day;
$next_day->add(new \DateInterval('P1D'));
$previous_day = clone $day;
$previous_day->sub(new \DateInterval('P1D'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment