我想计算 php 中当前时间 20 年前的日期。如何才能做到这一点。我无法以正确的方式计算出这一点。场景是:
我在 mysql 中有一个列 dob。现在我想检索所有年龄大于 20 岁且小于 25 岁的用户。 我正在使用 Doctrine orm
编辑
它工作正常,但发出警告:
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
最佳答案
尝试:
echo 'Today: '. date('Y-m-d') ."\n";
echo 'Today: '. date('Y-m-d', strtotime('-20 year')) ."\n";
参见:http://php.net/manual/en/function.time.php
编辑:
关于警告:要么忽略它,要么使用显式设置时区
date_default_timezone_set('...your zone here...');
参见:http://php.net/manual/en/function.date-default-timezone-set.php
关于php - 如何在PHP中从当前时间获取过去的一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2216457/