PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 8th, 2013, 04:19 AM
Timmeyy Timmeyy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 18 Timmeyy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 55 m 59 sec
Reputation Power: 0
PHP-General - Get upcomming birthdays

Hey, I hope someone can help me with the following:

I need to get a list of users from a mysql database with birthdays in the upcomming week. dateOfBirth in the database are saved as php time( );

Cheers
Tim

Reply With Quote
  #2  
Old January 8th, 2013, 04:45 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,872 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
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.

Reply With Quote
  #3  
Old January 8th, 2013, 05:06 AM
Timmeyy Timmeyy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 18 Timmeyy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 =_="

Thanks anyway

Reply With Quote
  #4  
Old January 8th, 2013, 05:10 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,872 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 1 h 24 m 30 sec
Reputation Power: 813
You can create the date values on the fly with FROM_UNIXTIME().

But my "equation" is wrong, because the counting starts with sunday (so sunday is 1 instead of 7). I have to think about that a bit more.

Reply With Quote
  #5  
Old January 8th, 2013, 05:34 AM
Timmeyy Timmeyy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 18 Timmeyy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 55 m 59 sec
Reputation Power: 0
Ill be honest, I'm incredibly bad at this date stuff, but right now I have the follow code to get birthdays:

The Query:
PHP Code:
 $result $this->Database->prepare
("SELECT *,(FROM_UNIXTIME(`dateOfBirth`)) as 'bday' FROM `member` 
WHERE `dateOfBirth` != '' "
)            
 ->
execute();         
return 
$result->fetchAllAssoc(); 


The Convertion
PHP Code:
foreach( $users as $key => $data ){             
if( !empty(
$data['bday'])) {                 
   list(
$date$time) = explode(' '$data['bday']);                 
   list(
$year,$m,$d) = explode('-'$date);                 
   
$new_date date('Y') . '-' $m '-' $d;                               
   
$now time();                 
   
$end $now + (60*60*24*7);                 
   
$bday strtotime($new_date);                                  
   if(
$bday $end && $bday $now )                 {                     
echo 
$user['firstname'] . ' - ' .$data['bday'] . <br/>';                 
}            
}         



If you know easier or better solution i'm all ears :P

Reply With Quote
  #6  
Old January 8th, 2013, 08:15 AM
Triple_Nothing Triple_Nothing is online now
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 297 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
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.

Reply With Quote
  #7  
Old January 8th, 2013, 11:12 AM
Rhytz's Avatar
Rhytz Rhytz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 100 Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level)Rhytz User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 11 h 4 m 50 sec
Reputation Power: 50
Are you still using the time() function?

If so, you could simply do:
Code:
SELECT birthday FROM table WHERE birthday >= ".time()." AND birthday <= ".time() + 518400."


Shame on me, but I often use the time() function in mysql

Reply With Quote
  #8  
Old January 8th, 2013, 11:27 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,809 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
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.
Comments on this post
Rhytz agrees: Stupid me
Triple_Nothing agrees: Wow. Nice catch. Such a blonde moment for me. :-P
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"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

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Get upcomming birthdays

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap