473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trying to Find Who's Birthday

I have a DATE field on a mysql db that stores users birthdays (the month
and the day, the year doesn't matter). I am trying to have a query that
returns the names of those whose birthdays are today. Currently I am
returning everyones birthdays and then looping through them doing a
string comparison. Can't I do this work in the query?

Something like:
$bday_qry="SELECT user_fname, user_lname, user_bday
FROM users
WHERE DATE_FORMAT(user_bday, %m-%d)==".date("m-d");

What's the best way to do this?
Thanks,
Steve
Jul 17 '05 #1
2 2152
Noyb, being the foo Noyb is, wrote:
I have a DATE field on a mysql db that stores users birthdays (the
month and the day, the year doesn't matter). I am trying to have a
query that returns the names of those whose birthdays are today.
Currently I am returning everyones birthdays and then looping through
them doing a string comparison. Can't I do this work in the query?

Something like:
$bday_qry="SELECT user_fname, user_lname, user_bday
FROM users
WHERE DATE_FORMAT(user_bday, %m-%d)==".date("m-d");

What's the best way to do this?
Thanks,
Steve


Sure, you can simple select the birthdays for the current day in the WHERE
clause.
$current_date = getdate(); //www.php.net/getdate for reference
$bday_qry = "SELECT ";
$bday_qry.= "user_fname, user_lname, DATE_FORMAT(user_bday, '%m-%d') AS bday
";
$bday_qry.= "WHERE "
$bday_qry.= "MONTH(user_bday) = '" . $current_date['mon'] . "' AND
DAYOFMONTH(user_bday) = '" . $current_date['mday'] . "' AND YEAR(user_bday)
= '" . $current_date['year'] . "'";

That should do it I think =D.
--
Sharif T. Karim
....you don't know wrath yet...
Jul 17 '05 #2
Sharif T. Karim wrote:
Noyb, being the foo Noyb is, wrote:
I have a DATE field on a mysql db that stores users birthdays (the
month and the day, the year doesn't matter). I am trying to have a
query that returns the names of those whose birthdays are today.
Currently I am returning everyones birthdays and then looping through
them doing a string comparison. Can't I do this work in the query?

Something like:
$bday_qry="SELECT user_fname, user_lname, user_bday
FROM users
WHERE DATE_FORMAT(user_bday, %m-%d)==".date("m-d");

What's the best way to do this?
Thanks,
Steve

Sure, you can simple select the birthdays for the current day in the WHERE
clause.
$current_date = getdate(); //www.php.net/getdate for reference
$bday_qry = "SELECT ";
$bday_qry.= "user_fname, user_lname, DATE_FORMAT(user_bday, '%m-%d') AS bday
";
$bday_qry.= "WHERE "
$bday_qry.= "MONTH(user_bday) = '" . $current_date['mon'] . "' AND
DAYOFMONTH(user_bday) = '" . $current_date['mday'] . "' AND YEAR(user_bday)
= '" . $current_date['year'] . "'";

That should do it I think =D.


Thanks Sharif!
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Sandra | last post by:
I was given this problem for extra credit and I am just stuck ! BTW - I am not asking for source code and I am not asking anyone to do my homework as I do want to learn .. I just need a hint or two...
1
by: Claude Alain | last post by:
Hello! We are a small non-profit organisation with about 400 members. We have created a database using Access97 which contains tombstone information on our members, including home adresses and...
2
by: Crimsonwingz | last post by:
Trying again for understanding and comprehension. Simple database. Name, birthday, age. Name and birthday are provided. From a form (yes, I need to do it this way), I would like to click a...
2
by: edwin van rutten | last post by:
Hi I have a personal database of all adresses etceteras of personal contacts and want to sort the birthday dates in such a way that I have a chronological list for this years birthdays. The...
2
by: David Garamond | last post by:
What would be the more proper way of storing birthday data? It will be used to send out birthday messages for customers ("Happy 30th birthday, Sam!"). But the date of birth is not necessarily known...
0
by: Wolf | last post by:
Hi I am using the outlook add in for vs.net 2005 and outlook 2003. I am creating contacts in outlook from our system The clients want to see only the birthdate's and dont want to be bugged...
23
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that...
13
kestrel
by: kestrel | last post by:
Sheila and He-Man are twins; Sheila is the OLDER twin. Assume they were born immediately after each other, an infinitesimally small - but nonzero - amount of time apart. During one year in the...
1
by: stilldancin12 | last post by:
Ok so i have to write an application that asks for the users birthday and replies with they day of the week in which he or she is born on, using the java program. This is what I have so far.It gives...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.