PHP计算两个时间的年数、月数以及天数

如何获取两个不同时间相差几年几月几日呢?比如当前时间距离2008年08月08日的北京奥运会有几年几月几日了?需要说明的是:1、定义一年为360天,一个月为30天;2、代码中86400=24*60*60,代表一天中共有多少秒;3、这两个时间都要规范的写成类似2013-07-28的形式;4、推广到所有的PHP程序,可以把Get_option('swt_builddate')这个wordpress获取后台数据的参数改成需要比较的时间参数。具体代码如下:

<?php
  //Get detail gap of year,month and days between two different time by vfhky 20130728
  $common = (time()-strtotime(get_option('swt_builddate')));
  $a = floor($common/86400/360);//整数年
  $b = floor($common/86400/30) - $a*12;//整数月
  $c = floor($common/86400) - $a*360 - $b*30;//整数日
  $d = floor($common/86400);//总的天数
  echo $a."年".$b."月".$c."日(共计".$d."天)";
?>
原文地址:https://www.cnblogs.com/shanmao/p/3299149.html