3

所以我用这种方法来得到两个日期之间的差异。

$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

现在,假设我想将年份和月份转换为天。我怎么做?

4

2 回答 2

5

使用DateTime它是小菜一碟:

$date1 = new DateTime($date1);
$date2 = new DateTime($date2);

$diff = $date1->diff($date2, true);

echo $diff->format('%a') . ' days';
于 2012-12-11T13:29:27.883 回答
0
$currentDate = date("d-m-Y");
$date1 = date_create("".$joining_date."");
$date2 = date_create("".$currentDate."");
$diff12 = date_diff($date2, $date1);
$hub_days = $diff12->days;
$months = $diff12->m;
$years = $diff12->y;
于 2014-05-19T11:04:07.537 回答