我的日期格式为day::month::year-hms
现在我只想以天为单位取这两个日期之间的差额?
you can do this way
$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;
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 means (+) or (-) you can use only %a.
Try this
$dateDiff=date_diff(date_create($date1),date_create($date2));
echo $dateDiff->format("%a days");
try this one
$fisrstDate = new DateTime(date('Y-m-d', strtotime($fisrstDate)));
$secondDate = new DateTime(date('Y-m-d', strtotime($secondDate)));
echo $fisrstDate->diff($secondDate)->days;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.