Skip to content

Instantly share code, notes, and snippets.

@zgulde
Created June 16, 2016 03:49
Show Gist options
  • Select an option

  • Save zgulde/52c36152fede0130cce742f0e3f77e37 to your computer and use it in GitHub Desktop.

Select an option

Save zgulde/52c36152fede0130cce742f0e3f77e37 to your computer and use it in GitHub Desktop.
<?php
// takes a start and end date as a string and returns the number of days
// between them
function diffInDays($start, $end)
{
$start = new DateTime($start);
$end = new DateTime($end);
return date_diff($start, $end)->days;
}
diffInDays('today', 'dec 25'); // 191
diffInDays('2015-01-24', '2015-01-24'); // 0
diffInDays('2015-01-24', '2015-02-07'); // 14
diffInDays('2015-01-24', '2015-05-13'); // 109
diffInDays('2015-01-24', '2016-04-24'); // 456

ghost commented Jun 16, 2016

Copy link
Copy Markdown

Thanks Zach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment