Skip to content

Instantly share code, notes, and snippets.

@abacaj
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abacaj/ce27e02b77e640b7ec75 to your computer and use it in GitHub Desktop.
Save abacaj/ce27e02b77e640b7ec75 to your computer and use it in GitHub Desktop.
/*
this function will take in a due date and determine the remaining days until something is due from the current date.
*/
public function calculateDate($due_date)
{
$future = strtotime($due_date);
$now = time();
$timeleft = $future-$now;
$daysleft = round((($timeleft/24)/60)/60);
return $daysleft;
}
/*
example usage:
$duedate = '2014-12-12'
$remainingdays = $this->calculateDate($duedate);
echo "days remaining are:" . $remainingdays; // output: "days remaining are: 99 days" - from 2014-09-03 to 2014-12-12.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment