Created
August 9, 2019 12:52
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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