如何仅在给定月份和年份时计算

时间:2017-08-30 03:35:24

标签: php date datediff date-difference

我有两个字符串如下。

enter image description here

如何在PHP中区分它们?

我尝试过以下代码

<?php echo date_diff(date_create($experience[$i]->StartWork),date_create($experience[$i]->EndWork))->format("%a days"); ?>

2 个答案:

答案 0 :(得分:1)

你可以简单地这样做

 <?php
 $date1 = "may 1994";
 $date2 = "august 1997";
 $diff = strtotime($date2)-strtotime($date1);
 $days = $diff / (60*60*24*1);
 echo "days :". $days;
 ?>

演示:: https://eval.in/852242

答案 1 :(得分:0)

$date1 = new DateTime("may 1994"); //$experience[$i]->StartWork
$date2 = new DateTime("august 1997"); //$experience[$i]->EndWork
$interval = $date1->diff($date2);


echo "days diff = " . $interval->days ;