Skip to content

Instantly share code, notes, and snippets.

@cdmz
Created August 4, 2015 12:00
Show Gist options
  • Save cdmz/54ff86ef73fd4034774f to your computer and use it in GitHub Desktop.
Save cdmz/54ff86ef73fd4034774f to your computer and use it in GitHub Desktop.
Function print days left birthday
<?php
function daysLeftForBirthday($birthdate) {
/* input date format -> Y-m-d */
list($y, $m, $d) = explode('-',$birthdate);
$nowdate = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$nextbirthday = mktime(0,0,0,$m, $d, date("Y"));
if ($nextbirthday<$nowdate)
$nextbirthday=$nextbirthday+(60*60*24*365);
$daycount=intval(($nextbirthday-$nowdate)/(60*60*24));
return $daycount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment