I have user´s birthday stored in birthday
as 1999-02-26.
How can I check if the birthday is today?
if(date('m-d') == ..?
<? php function birthday_today(){ $current_date = date('m-d'); $row = mysql_query("SELECT `username`, `birthday` FROM `users` WHERE MONTH(birthday) = MONTH(NOW()) AND DAY(birthday) = DAY(NOW())"); if (date('m-d', strtotime($row['birthday'])) == date('m-d')) { return '<ul><li>' .
From PHP 5.2 upwards: if (substr($dateFromDb, -5) === date_create()->format('m-d')) { // Happy birthday! }
There is a distinction between birthday and birthdate: the former, except for February 29, occurs each year (e.g. January 15), while the latter is the complete date when a person was born (e.g. January 15, 2001).
This answer should work, but it depends on strtotime
being able to figure out your database's date format:
$birthDate = '1999-02-26'; // Read this from the DB instead
$time = strtotime($birthDate);
if(date('m-d') == date('m-d', $time)) {
// They're the same!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With