473,403 Members | 2,323 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,403 software developers and data experts.

Birthdays

In a MYSQL database I have stored when the members were born in the form
"YYYYMMDD". Now I want a method to select every member who has birthday from
today and up to 30 days into the future. I would prefer if this could be
done in a MYSQL query.

Can anyone tell me how to do this? I have figured out some solutions that
will work, but unfortunately not in December because the year will turn.

/ Bo

Jun 23 '07 #1
3 1586
In our last episode, <f3****************@newsb.telia.net>, the lovely and
talented Bo Wisén broadcast on comp.lang.php:
In a MYSQL database I have stored when the members were born in the form
"YYYYMMDD". Now I want a method to select every member who has birthday from
today and up to 30 days into the future. I would prefer if this could be
done in a MYSQL query.
Well then, this would seem to be a MySQL question. See 'Date and Time
Functions' in the MySQL Manual.
Can anyone tell me how to do this? I have figured out some solutions that
will work, but unfortunately not in December because the year will turn.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 576 days to go.
Owing to googlegroups not screening users to eliminate spammers and other
USENET abusers, I do not see most posts from googlegroups.
Jun 23 '07 #2
In our last episode, <sl********************@goodwill.larseighner.com >, the
lovely and talented Lars Eighner broadcast on comp.lang.php:
In our last episode, <f3****************@newsb.telia.net>, the lovely and
talented Bo Wisén broadcast on comp.lang.php:
>In a MYSQL database I have stored when the members were born in the form
"YYYYMMDD". Now I want a method to select every member who has birthday from
today and up to 30 days into the future. I would prefer if this could be
done in a MYSQL query.
Well then, this would seem to be a MySQL question. See 'Date and Time
Functions' in the MySQL Manual.
>Can anyone tell me how to do this? I have figured out some solutions that
will work, but unfortunately not in December because the year will turn.

Okay, I give up. You made me think about this enough to figure it out.
I'm going to express this in words, you look up the MySQL functions
1. Find the difference between today and subject's birthday this year.

Compose subject's birthday this year by extracting the year from the
current date and the month and day from the subjects birthdate.

DATEDIFF will return the difference in days.

2. Devise the test that will work before December. That would be
if the date difference is equal or greater than zero AND less than
31 (hits on today and today + 30 days, but not today +31 days)

However this misses when today is after Dec. 1 and subjects birthday is
before Jan. 30. So this test had to be ORed with another test.

2. Devise the rest of the test.

Find the number of days in this year. (This is to account for the
possibility that this is a leap year). Do this by finding out what is the
day number of Dec 31 this year.

Subtract 30 from this (could be off by one, check in testing).

Negate the result.

so the ORed test should be date diff in days < result just obtained.
--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 576 days to go.
Owing to googlegroups not screening users to eliminate spammers and other
USENET abusers, I do not see most posts from googlegroups.
Jun 23 '07 #3
Bo Wisén wrote:
In a MYSQL database I have stored when the members were born in the form
"YYYYMMDD". Now I want a method to select every member who has birthday from
today and up to 30 days into the future. I would prefer if this could be
done in a MYSQL query.
You mean it is stored as a string (or integer)? Store it as a proper date.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 3 days, 2:24.]

A New Look for TobyInkster.co.uk
http://tobyinkster.co.uk/blog/2007/06/22/new-look/
Jun 23 '07 #4

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

Similar topics

2
by: Stijn Goris | last post by:
hi all, I have this problem that I cant solve. I have created an agenda (http://28edegem.scoutnet.be/agenda.php) . The agenda contains events and birthdays of the members. I query the events...
4
by: Tarscher | last post by:
Hi all, I have a l list of persons and birthdays (stored as a date eg: 1980-07-11). I want to query the 4 first persons that will have their birtday. Can this be done via query? Thanks in...
2
by: Chandrashekara Adiga | last post by:
hi This is particular to Containment classes .. ( just taking an example from rougewave ) Can someone point out How destrutor of new RWDate(2, "Nov", 1980) will be called? Is is our...
7
by: Fred Thompson | last post by:
I'm using MS SQL 2000 server. I have a table which includes a date field which has people's birthdays in it. How can I write a query to return all the records of people with birthdays within the...
3
by: ClassicNancy | last post by:
I have this mod for my forum and it calls the birthdate from the database. I would like to have it not see the year. What is happening if a person puts a year in the box in their profile it makes it...
0
by: ClassicNancy | last post by:
I have this mod for my forum and it calls the birthdate from the database. I would like to have it not see the year. What is happening if a person puts a year in the box in their profile it makes it...
1
by: Mark Scott | last post by:
Hi I have limited experience with ASP.NET but have had an idea for a functionality I would like to add to our intranet site. I would like to put an announcement on the front page when a member...
4
by: HariKutty | last post by:
Hello every one, I am working in Asp.Net 2005 web Application.I am storing my employees Details in the Database that includes there Birthday dates,Emailid.So my task is automatically mail should...
6
by: onlyshanks28 | last post by:
Hi I have a database birthday containing name and DOB, I want to find the query which can display 3 latest birth day. I tried select name,date from birthday where...
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: 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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.