Date
Object and the DateInterval()
Function Together
$checkout_length = new DateInterval('P3W');
$due_date = new DateTime();
$due_date->add($checkout_length);
$voting_age = new DateInterval('P18Y');
$dob = new DateTime(); $dob->sub($voting_age);
echo("<p>You can vote if you were born on or before ' . $dob->format('n/j/Y') . "</p>\n");
You can vote if you were born on or before 6/18/2007?p>
$now = new DateTime('2020-09-13 12:45:00');
$due = new DateTime('2021-04 last day of midnight');
$time_span = $now->diff($due);
echo("<p>"Time between " . $now->format('m/d/Y h:m') . " and " . $due->format('m/d/Y h:m') . " is: " . $time_span->format('%R%dd %H:%I:%Sh') . "</p>\n"); // '-15d 12:45:00h'
Time between 09/13/2020 12:09 and 04/30/2021 12:04 is: +16d 11:15:00h