Skip to content

Instantly share code, notes, and snippets.

@stojg
Created November 3, 2014 09:53
Show Gist options
  • Save stojg/45536da87b6776792528 to your computer and use it in GitHub Desktop.
Save stojg/45536da87b6776792528 to your computer and use it in GitHub Desktop.
datetest.php
<?php
$dateFrom = DateTime::createFromFormat('d/m/Y', '03/11/2014');
$dateTo = DateTime::createFromFormat('d/m/Y', '02/01/2015');
$difference = $dateFrom->diff($dateTo);
// diff in years, months and years
echo $difference->y.' '.$difference->m.' '.$difference->d.PHP_EOL;
// reformat into days only
echo $difference->format('%R%a days');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment