Skip to content

Instantly share code, notes, and snippets.

@zmiftah
Last active August 29, 2015 14:17
Show Gist options
  • Save zmiftah/049792f40b5ecced5409 to your computer and use it in GitHub Desktop.
Save zmiftah/049792f40b5ecced5409 to your computer and use it in GitHub Desktop.
DateTime and DateInterval Function
<?php
function getDateFromNow($interval='P1D', $direction='add') {
$currentDate = new DateTime;
$intervalDate = new DateInterval($interval);
if ($direction == 'sub') {
$resultDate = $currentDate->sub($intervalDate);
} else {
$resultDate = $currentDate->add($intervalDate);
}
return $resultDate->format('Y-m-d H:i:s');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment