Click to See Complete Forum and Search --> : change date year


kproc
12-10-2006, 08:08 PM
hi

I have a table with a persons year of birth and the below query that I want to display names if bday is within xdays

how do I change the bday to set the year to the current year

$today = strtotime("Now");
$leadDate = strtotime("+250 day", $today);

$thisdate = date("Y-m-d", $leadDate);
echo $thisdate;

$get_childdob = mysql_query("SELECT owner_id, childdob FROM children WHERE childdob BETWEEN CURDATE() AND '$thisdate'")or die (mysql_error());

chazzy
12-10-2006, 08:29 PM
you'll want to look at one of the many date and time functions that mysql gives.

http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html

For one, you should do that calculation of "lead date" using your query, not PHP, as it'll be easier to find this way.

as for converting it, use "makedate"

kproc
12-10-2006, 08:38 PM
my mysql knowledge is very limited. when I was googling I found that but cannot figure out how to do what i need

kproc
12-10-2006, 08:46 PM
this is what I'm trying, am I on the wirte track

$get_childdob = mysql_query("SELECT owner_id, year(CURDATE()), month(childdob), day(childdob) as newdate FROM children WHERE newdate BETWEEN CURDATE() AND '$thisdate'")or die (mysql_error());

chazzy
12-11-2006, 06:19 AM
Please look at the link I gave you. there is a function called "MAKEDATE" taht takes the year, month and day and turns them into a date/time type.

it's what you need to do this.