Get users born today

If you need a sql statement or a php script to return all the users born today, here is how you do it:

SELECT *
FROM [users_table]
WHERE DAYOFMONTH( [date_of_birth_field] ) = DAYOFMONTH(NOW())
AND MONTH( [date_of_birth_field] ) = MONTH(NOW())

The php code is this:

$sql_text = "SELECT * FROM [users_table]
WHERE DAYOFMONTH( [date_of_birth_field] ) = DAYOFMONTH(NOW())
AND MONTH( [date_of_birth_field] ) = MONTH(NOW())";
$results_query = mysql_query($sql_text);
while($results = mysql_fetch_array($results_query)){
   // do something with the returned values: $results[0]...
}

Change [users_table] and [date_of_birth_field] with your table name and table field.

Tags: , ,

Popularity: 5% [?]


1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Check out this video!!

Write a Comment

Take a moment to comment and tell me what you think. Some basic HTML is allowed for formatting.

*
To prove that you're not a bot, enter this code
Anti-Spam Image

Type your comment here.

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Reader Comments

$azid=date(”m-d”);
mysql_query (”select * from useri where right(data_nasterii,5)=’$azid’ “);

asta de ce nu e bun? :P

E ok numai daca ai data nasterii intr-un anumit format… :)

Pai in formatul DATE din mysql, ca doar n-o s-o pui in datetime, numai daca stii si minutul si secunda in care te-ai nascut :P

…si daca e text in formatul dd/mm/yy ?!? :P

atunci pui right(data_nasterii …) :razz:

N-am zis ca nu e bine, doar ca trebuie sa tii cont de formatul in care sunt stocate informatiile - http://dev.mysql.com/doc/refman/4.1/en/datetime.html .
In cazul scriptului propus de mine nu trebuie sa-ti pui astfel de probleme…

dupa cum vad eu acolo ( si cum stiam si inainte ) in mysql DATE e in formatul an-luna-si , si DATETIME in an-luna-zi ora-min-sec ( nu conteaza delimitatorul, adica poate fi si an/luna/zi ).

Tocmai la asta m-am referit si eu… formatul poate sa aiba alt delimitator decat ‘-’ si atunci trebuie sa modifici $azid=date(”m-d”); sau poate sa nu aiba delimitator si atunci trebuie sa modifici in query: right(data_nasterii,4) …
Pentru tine e usor sa schimbi astea, dar pentru cineva care nu prea stie e mai bine sa foloseasca scriptul postat de mine :)

aaaa nuuu .. deci in mysql asa e data : aaaa-ll-zz oo:mm:ss . tu poti sa-ti dai alt format numai cand o modifici ( update ), dar stocata e numai asa cum zic mai sus. sau nu? :neutral:

Nici mie nu mi-e foarte clar ce vor sa spuna cei de la mysql :)