两个日期之间的差异,并使用php在输入中显示


difference between two date and display it in input by using php

可能重复:
如何使用PHP计算两个日期之间的差异?

我有三个html输入。其中两个是开始日期和结束日期,第三个是找出它们之间的差异并显示结果。

这是输入:

<p><span>Start date:</span> <input type="date" required min="2012-01-01" name="start_d" id="start_d" ><span>* Format: YYYY-MM-DD</span><br></p>
<p><span>End date:</span> <input type="date" required min="2012-01-01" name="end_d" id="end_d" ><span>* Format: YYYY-MM-DD</span><br></p>
<p><span>Duration :</span><input type="text" required name="duration" id=duration" readonly="readonly"><br></p>
$date1 = new DateTime("2011-02-01");
$date2 = new DateTime("2012-01-01");
$duration = $date1->diff($date2);
var_dump($duration);
date('Y-m-d', (strtotime($str_start_date) + round((strtotime($str_end_date) - strtotime($str_start_date)) / 2))';

编辑:

误解了你的问题。虽然你想要这两人之间的约会?你想要以秒为单位的差异吗?

round((strtotime($str_end_date) - strtotime($str_start_date)) / 2)

看看http://php.net/manual/en/function.date-diff.php以及如何使用PHP计算两个日期之间的差异?