我的日期格式为day::month::year-h-m-s
现在我想仅在几天内区分这两个日期?
答案 0 :(得分:1)
你可以这样做
$date1 = new DateTime(date('Y-m-d', strtotime("2013-08-07 13:00:00")));
$date2 = new DateTime(date('Y-m-d', strtotime("2013-08-08 12:00:00")));
echo $date1->diff($date2)->days;
答案 1 :(得分:1)
PHP:
<?php
$otherday = date_create("01-05-2015");
$today= date_create(date("d-m-Y"));
$days = $today->diff($otherday);
echo $days->format("%R%a");
?>
%R表示(+)或( - )您只能使用%a。
答案 2 :(得分:1)
试试这个
$dateDiff=date_diff(date_create($date1),date_create($date2));
echo $dateDiff->format("%a days");
答案 3 :(得分:0)
尝试这个
$fisrstDate = new DateTime(date('Y-m-d', strtotime($fisrstDate)));
$secondDate = new DateTime(date('Y-m-d', strtotime($secondDate)));
echo $fisrstDate->diff($secondDate)->days;