如何使用PHP计算两个日期时间之间的差异?

时间:2012-04-11 06:21:39

标签: php

  

可能重复:
  How to calculate the difference between two dates using PHP?

我有两个日期:

Start Date: 2012-02-10 11:26:00
End Date: 2012-04-25 01:50:00

现在我需要找到以下两种形式之间的区别:

 years,  months, days, hours, minutes, seconds

我如何在PHP中执行此操作?

1 个答案:

答案 0 :(得分:0)

您可以使用DateTime::diff

$start_date = new DateTime("2012-02-10 11:26:00");
$end_date = new DateTime("2012-04-25 01:50:00");
$interval = $start_date->diff($end_date);
echo "Result " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";