944,065 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 6026
  • MySQL RSS
Jun 23rd, 2007
0

Help with birthday MySQL Script

Expand Post »
Ok this is what my table structure looks like:
username varchar(20)
eadd varchar(40) for email addresses
bday varchar(4) everyone is posting mmdd
emailques varchar(2) they answer yes or no
I want my query statement to tell me what birthdays are today and as a bonus email them on their birthday.
I tried:
select * from lpbdays where bday = curdate();

That didn't work the closest I got was when I did:
select * from lpdays where bday = 0622 (if I do it manually);

If anyone out there can help me out on this that would be great.

Thanks,
Elderp
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elderp is offline Offline
13 posts
since Mar 2007
Jun 23rd, 2007
0

Re: Help with birthday MySQL Script

I guess this is a problem with data types.

Try looking here. Curdate should return something like 2004-11-30. Date variables and string (varchars) cannot be compared directly.

You are storing your dates as 0622. So first you would have to convert the curdate() to a string, strip it of the hypens and take of the year.
Last edited by iamthwee; Jun 23rd, 2007 at 4:48 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jun 23rd, 2007
0

Re: Help with birthday MySQL Script

Thanks for the help, I actually did solve this issue (with some help from a European Discussion Board).
Here was my solution:
select * from lpbdays where bday =date_format(now(),'%m%d');
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elderp is offline Offline
13 posts
since Mar 2007
Jun 24th, 2007
0

Re: Help with birthday MySQL Script

Anyone know or have an idea how I can change this query so it will give me a result one day from now. For example I want it to give me a list of all the birthdays that will happen tommorow that way I can prepare for them.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elderp is offline Offline
13 posts
since Mar 2007
Jun 24th, 2007
0

Re: Help with birthday MySQL Script

Click to Expand / Collapse  Quote originally posted by elderp ...
Anyone know or have an idea how I can change this query so it will give me a result one day from now. For example I want it to give me a list of all the birthdays that will happen tommorow that way I can prepare for them.
I don't see why you would need to prepare this in advance. Databases are real time apps ya know.

select DATE_ADD('2007-06-27',INTERVAL 1 DAY);

See for further details...
http://dev.mysql.com/doc/refman/4.1/...nction_curdate
Last edited by iamthwee; Jun 24th, 2007 at 10:17 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jun 25th, 2007
0

Re: Help with birthday MySQL Script

Found a super simple solution:
select * from lpbdays where bday =(date_format(now(),\'%m%d\')+1)';
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elderp is offline Offline
13 posts
since Mar 2007
Sep 28th, 2007
0

Re: Help with birthday MySQL Script

I have a similar situation but I am storing my birthday as a date format yyyy-mm-dd. I need to search for birthdays from the current day up to 2 weeks. Thank you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
today31 is offline Offline
1 posts
since Aug 2007
Sep 30th, 2007
0

Re: Help with birthday MySQL Script

Maybe you could use something like:

MySQL Syntax (Toggle Plain Text)
  1. SELECT <whatever> FROM <TABLE_NAME> WHERE DATE >= 'starting date' AND DATE < 'ending date'

perhaps?

The ending date could be got by using the data_add (14 days) to the current date.
Last edited by iamthwee; Sep 30th, 2007 at 10:51 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Indexing and Query optimisation.
Next Thread in MySQL Forum Timeline: Trigger problem...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC