Discuss Get upcomming birthdays in the PHP Development forum on Dev Shed. Get upcomming birthdays PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 1,872
Time spent in forums: 1 Month 2 Weeks 2 Days 1 h 24 m 30 sec
Reputation Power: 813
Hi,
Quote:
Originally Posted by Timmeyy
dateOfBirth in the database are saved as php time( );
Why?? MySQL has a DATE type for exactly this purpose: to store dates. Using your own Unix seconds makes absolutely no sense -- unless you love to manually calculate dates.
So the first thing you should do is convert the seconds into actual date values. After that, you can use the date functions of MySQL.
The monday of next week is 9 - DAYOFWEEK(date) days after the current date.
Last edited by Jacques1 : January 8th, 2013 at 04:49 AM.
Posts: 18
Time spent in forums: 8 h 55 m 59 sec
Reputation Power: 0
Yes I know, I hate it too.. I also hate all this date conversion, gives me a big headache. The system works like this, I didn't make it, nor can I change it. I guess ill just go fetching all users and covert the birthdays one by one =_="
Posts: 297
Time spent in forums: 3 Days 8 h 45 m 39 sec
Reputation Power: 5
It sounds your simply wishing to select a range...? The range can be done as one of follows:
Code:
SELECT *,(FROM_UNIXTIME(`dateOfBirth`)) as 'bday' FROM `member` WHERE `dateOfBirth` >= [start date] AND `dateOfBirth` <= [end date]
SELECT *,(FROM_UNIXTIME(`dateOfBirth`)) as 'bday' FROM `member` WHERE `dateOfBirth` BETWEEN [start date] AND [end date]
As far as defining your start/end date, simply find current date, and if Day of Week is NOT equal to 1, then start date is the following day equaling 1, otherwise current date. End date is just add 6 days to that, so that should be no prob.
EDIT: Actually, I should ask this first. When you say birthdays in the UPCOMING week, do you mean the current day plus the next 6 days? Or if today is Tuesday, do you want birthdays for the next Sunday thru Saturday?
EDIT2: I figure I'd toss some options in to maybe help you speed this up and not have to wait...
PHP Code:
//if start day is current day
$start = time();
//if start day is set day of week
$start = strtotime("next Sunday");
//set 6 days later
$end = $start + 518400;
Then use a simple while() loop to echo your items and format your time/date, if format is removed from SELECT statement...
Date formating: http://php.net/manual/en/function.date.php
Hope this helps.
.
Last edited by Triple_Nothing : January 8th, 2013 at 09:53 AM.
Posts: 9,809
Time spent in forums: 2 Months 3 Weeks 18 h 6 m 48 sec
Reputation Power: 6112
Birthdays are not stored as "the person's next birthday," they're usually stored as "the person's day of birth," which means none of them are "upcoming" dates, you want the ANNIVERSARY of that date.
Luckily, we discussed this a while back and I provided a response.
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002