我有一个代码在运行,其中我将日期作为输入,并尝试获取这两个日期之间的天数差异。
尝试了各种选项,但结果没有意义
<form method="post" action="date_Results.php">
<input class="span2 ui-autocomplete-input" value="" id="start_date" name="start_date" autocomplete="off" type="text">
<input class="span2 ui-autocomplete-input" value="" id="end_date" name="end_date" autocomplete="off" type="text">
</form>
<?php
var_dump($_POST);
date_default_timezone_set('Europe/Amsterdam');
$D1 = $_POST['start_date'];
$D2 = $_POST['end_date'];
$frmt_D1 = $D1;
$frmt_D2 = $D2;
$date = new Datetime($frmt_D1);
$now = new Datetime($frmt_D2);
echo $date->diff($now)->format("%d");
?>
array (size=2)
'start_date' => string '13-07-2017' (length=10)
'end_date' => string '01-09-2017' (length=10)
19 ??? days for these two inputs
查询同一个月内的日期时结果是正确的
array (size=2)
'start_date' => string '12-07-2017' (length=10)
'end_date' => string '24-07-2017' (length=10)
12
即使日期格式发生变化,结果也不应该是
array (size=2)
'start_date' => string '2017-07-13' (length=10)
'end_date' => string '2017-12-31' (length=10)
18