proctk Posted December 10, 2006 Share Posted December 10, 2006 HI,I'm trying to find script to run a query that will list all birthdays within 20 days.the date is stored in a column DOB in a mysql table as yyyy-mm-ddany help is great Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/ Share on other sites More sharing options...
paul2463 Posted December 10, 2006 Share Posted December 10, 2006 [code]<?php$query = "SELECT * FROM "table" where "date" Between CURDATE() AND DATE_ADD(CURDATE(),INTERVAL 20 DAY)":?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-138503 Share on other sites More sharing options...
proctk Posted December 10, 2006 Author Share Posted December 10, 2006 below is what I have this far and it retuns nothing any idea why[code=php:0] include '../config/db.php';$today = strtotime("Now"); $leadDate = strtotime("+350 day", $today);$get_childdob = mysql_query("SELECT * FROM children WHERE childdob BETWEEN CURDATE() AND '$leaddate'")or die (mysql_error());while($row_get_childdob = mysql_fetch_assoc($get_childdob)){$name = $row_get_childdob['childfirstname'];echo $name;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-138507 Share on other sites More sharing options...
paul2463 Posted December 10, 2006 Share Posted December 10, 2006 yeah there was a fault in my origonal postif you are using PHP to obtain the date in the furture you need another line in there[code]$today = strtotime("Now"); $leadDate = strtotime("+350 day", $today);$thisdate = date("Y-m-d", $leadDate);$get_childdob = mysql_query("SELECT * FROM children WHERE childdob BETWEEN CURDATE() AND '$thisdate'")or die (mysql_error());[/code]please accept my apologies, other wise my ammeded post above should work too Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-138508 Share on other sites More sharing options...
proctk Posted December 11, 2006 Author Share Posted December 11, 2006 thank you for the update, it gave it a try and its no producing any results. I changed the +150 to 365I found the below code that gets the values but I don't know how to change it to show birthdays in x days[code=php:0]$get_childdob = mysql_query("SELECT owner_id,childdob,IF(DAYOFYEAR(childdob) < DAYOFYEAR(CURDATE()), DAYOFYEAR(childdob)+366,DAYOFYEAR(childdob))as birthdayofyear FROM children ORDER BY birthdayofyear")or die (mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-138728 Share on other sites More sharing options...
proctk Posted December 11, 2006 Author Share Posted December 11, 2006 I also found this but it return no resultsI played around with INTERVAL to make sure there was dates that would result in a positive query[code=php:0]$get_childdob = mysql_query("SELECT owner_id, childdob FROM children WHERE childdob Between CURDATE() AND DATE_ADD(CURDATE(),INTERVAL 366 DAY)")or die (mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-138737 Share on other sites More sharing options...
proctk Posted December 11, 2006 Author Share Posted December 11, 2006 I think I have deterimed part of t he problem. the date of birth will always be within the date range as it looking at the year of birth, we need to change the year of birth to the current YEAR. i have been googling for hours and connot figure this out Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-138761 Share on other sites More sharing options...
proctk Posted December 12, 2006 Author Share Posted December 12, 2006 There has to be a way to take a date from a table and change the year section of the date to the current year and then compare that date to the current year and display it if the date is within 20 days and once the date is past not to display it any more. I have seached google many times and I have not had any luck getting an answer to this question. I'm trying to limit it to one mysql query.help please Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-139397 Share on other sites More sharing options...
paul2463 Posted December 13, 2006 Share Posted December 13, 2006 the other way to do it instead of coverting the year is to go back tomy origonal post and calculte a date that is 20 days in the future[code]<?php$now = strtotime("Now"); $then = strtotime("+350 day", $now);$today = date("Y-m-d", $now);$date20 = date("Y-m-d", $then);$get_childdob = mysql_query("SELECT * FROM children WHERE childdob > '$today' && < '$date20'")or die (mysql_error());?>[/code]sorry for the delay in answering - work gets in the way of everything doesnt it? Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-140255 Share on other sites More sharing options...
artacus Posted December 13, 2006 Share Posted December 13, 2006 Yeah I saw he has a double post going on after I answered the question.Only problem with yours is that it will only work on, well children who haven't been born yet :)A birthdate is going to be stored as '1999-03-18' but you'll want it to match on March 18th of every year. Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-140264 Share on other sites More sharing options...
paul2463 Posted December 13, 2006 Share Posted December 13, 2006 good point artacusback to the drawing boardwill have another think Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-140324 Share on other sites More sharing options...
artacus Posted December 13, 2006 Share Posted December 13, 2006 paul, I gave him a query that does what he needs in the other thread.[url=http://www.phpfreaks.com/forums/index.php/topic,118386.0.html]http://www.phpfreaks.com/forums/index.php/topic,118386.0.html[/url] Quote Link to comment https://forums.phpfreaks.com/topic/30128-up-coming-birthday-query/#findComment-140471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.