Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:当一个人达到特定年龄时,如何获得日期?_Php_Date - Fatal编程技术网

PHP:当一个人达到特定年龄时,如何获得日期?

PHP:当一个人达到特定年龄时,如何获得日期?,php,date,Php,Date,我正在进行一项涉及日期的任务。我有一本书。现在我想知道这个人在几个月内达到特定年龄的日期 例如: A person is 250 months and 15 days old on 2010-1-25. On which date this person will become 300 months old? 功能签名可以是: function getReqDate( $startDate, $currAgeMonths, $currAgeDays, $reqAgeMonths ) {

我正在进行一项涉及日期的任务。我有一本书。现在我想知道这个人在几个月内达到特定年龄的日期

例如:

A person is 250 months and 15 days old on 2010-1-25.
On which date this person will become 300 months old? 
功能签名可以是:

function getReqDate( $startDate, $currAgeMonths, $currAgeDays, $reqAgeMonths  ) {
      //return date
}
查看以了解如何编写间隔。同样,PHP5.3.0+是必需的。

使用PHP函数,您可以获得您要查找的日期。e、 g

strtotime('+50 months', mktime());

由于您从出生日期计算当前年龄,因此我建议您也使用出生日期而不是当前年龄来计算用户300个月大的时间。以下为上述DateTime解决方案的等效值(不需要5.3):

第二个参数是生日时间戳,上面给出

Tue, 13 Oct 2015 00:00:00 +0200
进一步阅读:


这不是答案,但请考虑一下闰年需要做什么:你的规格。并考虑到(不包括2月)其他月份有30天和31天。
echo date('r', strtotime('+300 months', strtotime('1990-10-13')));
Tue, 13 Oct 2015 00:00:00 +0200
function getReqDate( $startDate, $currAgeMonths, $currAgeDays, $reqAgeMonths  ) {
      $unixStartDate = strtotime($startDate);
      $dateBirth = strtotime("-$currAgeDays months", strtotime("-$currAgeMonths months", $unixStartDate));
      return strtotime("+$reqAgeMonths months", $dateBirth);
}
function getReqDate($startDate, $reqAgeMonths ) {
  list($year,$month,$day) = explode('-',$startDate);
  $date = date("Y-m-d", mktime(12, 0, 0, $month+$reqAgeMonths, $day, $year ));
  return $date
}