Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Birthday check today´s date

Tags:

php

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') == ..?
like image 528
Johnson Avatar asked Oct 06 '10 14:10

Johnson


People also ask

How to get today birthdays in PHP?

<? 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>' .

How to check birthday in PHP?

From PHP 5.2 upwards: if (substr($dateFromDb, -5) === date_create()->format('m-d')) { // Happy birthday! }

Is birthday and date of birth same?

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).


1 Answers

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!
}
like image 128
Powerlord Avatar answered Oct 08 '22 04:10

Powerlord