473,815 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1599
In our last episode, <f3************ ****@newsb.teli a.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************ ********@goodwi ll.larseighner. com>, the
lovely and talented Lars Eighner broadcast on comp.lang.php:
In our last episode, <f3************ ****@newsb.teli a.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
2452
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 and birthdays per month and sort them on date. This method works fine for the events since they are all for the same year (eg 2003) but doesnt work for the birthdays because someone born in 1980-06-23 will be sorted before someone born in...
4
2329
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 advance Stijn
2
4517
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 responsibilty to call it or such container after deleting the list element calls the destuctor also .
7
16225
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 next 30 days? (Based on system date as the starting point.) Actual year of birthday is irrelevant. Also the next 30 days may span into the next month, or the next year.
3
1752
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 Dec 31st because that year is already over. There is no way to remove that box from the code according to the forum tech people. I've added the two pieces that refer to date. It already is written where it only shows the month and day in the...
0
1012
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 Dec 31st because that year is already over. There is no way to remove that box from the code according to the forum tech people. I've added the two pieces that refer to date. It already is written where it only shows the month and day in the view. ...
1
1104
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 of staff has a birthday by searching through the staff db (around 250) for a match of todays date. I am not expecting a full listing but any pointers would be welcomed (I
4
1808
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 be sent the particular employee whose birthday matches with the current server date.how can i implement this in VS2005 ???. can anyone help me out.
6
7596
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 month(dob)>=month(curdate()) limit 3; But the problem here is that on 31-December-2008 it will not display the birthdays on January.
0
9610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10427
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9225
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3886
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.