Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with field type & simple query 1

Status
Not open for further replies.

Bajwa11

IS-IT--Management
Apr 19, 2005
30
0
0
US
I have a simple mysql database for my website. It stores contact information basically.I was thinking of a way to add date of births to this database. What is the best was to add this to my database. can i simply choose the field type of date? i ask this question because i dont think i would be much concerned with the year of the birth and i want to store just the month and date.

moreover once i have added the field i would like to run a sql query on a webpage to list the names of the people whose birthdays are coming up within the next few days ( like within the next week )

ANy ideas on what field type ( or how to store the date of birth ),and secondly the query that would run for that . once the field has been added

[highlight]
M.Bajwa
[/highlight]
 
The field to add to your table should be a date type. The basic SQL query that would do that is:

Code:
alter table [yourTable] ADD [fieldName] DATE;

There are a lot of ways to do the select query! I suggest you use DAYOFYEAR() to compare the date.

Code:
SELECT * FROM yourTable WHERE DAYOFYEAR(birthday) BETWEEN DAYOFYEAR(NOW()) AND DAYOFYEAR(NOW())+7;
 
hey sylve . sorry i couldn't try this for quite a while. I always thought it would take quite a while to implement this.

Anyways i got down today and in about 2 minutes , I had the query running because of your bright idea. Thanx a bunch.


My next mission is to schedule a cron job to email me every week with the names of peoples whose birthday lies between that week !

Thanx again


[highlight]
M.Bajwa
[/highlight]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top