我想知道找到两个日期差异的方法。我从表单中获取startDate和endDate。现在我想找到当前日期与startDate或endDate的区别。
echo $startDate = $startYear.'-'.$startMonth.'-'.$startDay.'<br>';
echo $endDate = $endYear.'-'.$endMonth.'-'.$endDay;
$_SESSION['startDate'] = $startDate;
$_SESSION['endDate'] = $endDate;
$_SESSION['team'] = $team;
header('location:test.php');
test.php的
date_default_timezone_set('Asia/Kuala_Lumpur');
echo $startDate = $_SESSION['startDate'];
$date2=date_create(date('Y/m/d'));
$diff=date_diff($startDate,$date2);
echo $diff->format("%R%a days");
答案 0 :(得分:0)
试试这个。
$date1=strtotime("2016-07-02");
$date2=strtotime(date('Y/m/d'));
$diff = $date2 - $date1;
echo ($diff / (60 * 60 * 24)) . ' days';