User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 426,140 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,718 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 2320 | Replies: 7
Reply
Join Date: Mar 2007
Posts: 13
Reputation: elderp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
elderp elderp is offline Offline
Newbie Poster

Help with birthday MySQL Script

  #1  
Jun 23rd, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,782
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Help with birthday MySQL Script

  #2  
Jun 23rd, 2007
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 3:48 am.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Join Date: Mar 2007
Posts: 13
Reputation: elderp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
elderp elderp is offline Offline
Newbie Poster

Re: Help with birthday MySQL Script

  #3  
Jun 23rd, 2007
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');
Reply With Quote  
Join Date: Mar 2007
Posts: 13
Reputation: elderp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
elderp elderp is offline Offline
Newbie Poster

Re: Help with birthday MySQL Script

  #4  
Jun 24th, 2007
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.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,782
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Help with birthday MySQL Script

  #5  
Jun 24th, 2007
Originally Posted by elderp View Post
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 9:17 am.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Join Date: Mar 2007
Posts: 13
Reputation: elderp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
elderp elderp is offline Offline
Newbie Poster

Re: Help with birthday MySQL Script

  #6  
Jun 24th, 2007
Found a super simple solution:
select * from lpbdays where bday =(date_format(now(),\'%m%d\')+1)';
Reply With Quote  
Join Date: Aug 2007
Posts: 1
Reputation: today31 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
today31 today31 is offline Offline
Newbie Poster

Re: Help with birthday MySQL Script

  #7  
Sep 28th, 2007
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.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,782
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Help with birthday MySQL Script

  #8  
Sep 30th, 2007
Maybe you could use something like:

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 9:51 am.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 4:55 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC