Skip to content

Instantly share code, notes, and snippets.

@zainulhasan
Created August 9, 2019 12:52
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 zainulhasan/b81fd9f8dc4b3ee0a8fd574d394807cc to your computer and use it in GitHub Desktop.
Save zainulhasan/b81fd9f8dc4b3ee0a8fd574d394807cc to your computer and use it in GitHub Desktop.
Helper function to calculate renaming days in birthday. If birthday is already passed then function calculate days according to next coming year.
function get_birthday_days($birthday)
{
$cur_day = date('Y-m-d');
$cur_time_arr = explode('-', $cur_day);
$birthday_arr = explode('-', $birthday);
$days=0;
$cur_year_b_day = $cur_time_arr[0] . "-" . $birthday_arr[1] . "-" . $birthday_arr[2];
if (strtotime($cur_year_b_day) < time()) {
$cur_year_b_day = date('Y', strtotime('+1 year')) . "-" . $birthday_arr[1] . "-" . $birthday_arr[2];
$diff = strtotime($cur_year_b_day) - time();
$days = floor($diff / (60 * 60 * 24));
} else {
$diff = strtotime($cur_year_b_day) - time();
$days = floor($diff / (60 * 60 * 24));
}
return $days;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment