可能重复:
How to calculate the difference between two dates using 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>
答案 0 :(得分:1)
$date1 = new DateTime("2011-02-01");
$date2 = new DateTime("2012-01-01");
$duration = $date1->diff($date2);
var_dump($duration);
答案 1 :(得分:0)
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)
答案 2 :(得分:0)