views:

124

answers:

1

I want to calculate whats the date 20 yrs back from current time in php.How can do that.I am not able to figure this out in a proper manner. Scenario is:

I am having a column dob in mysql. Now i want to retrieve all the users who age is more than 20yrs and less than 25 yrs. I am using doctrine orm

Edit

Its working fine but giving a warning:

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Calcutta' for '5.5/no DST' instead in C:\xampp\htdocs\fanyer\test.php on line 11 Today: 2010-02-07

+5  A: 

Try:

echo 'Today: '. date('Y-m-d') ."\n";
echo 'Today: '. date('Y-m-d', strtotime('-20 year')) ."\n";

See: http://php.net/manual/en/function.time.php

Edit:

About the warning: either ignore it, or explicitly set the time-zone using

date_default_timezone_set('...your zone here...');

See: http://php.net/manual/en/function.date-default-timezone-set.php

Bart Kiers