計算兩個日期相差幾天
<?php function DateDiff($beginDate, $endDate) { $_beginDate = strtotime($beginDate); $_endDate = strtotime($endDate); $_diff = abs($_beginDate-$_endDate); return round(($_diff)/3600/24); } ?>
<?php $a = "2015-12-31"; $b = "2015-10-31"; echo "日期a:".$a."\n"; echo "日期b:".$b."\n"; echo "兩個日期相差:".DateDiff($a, $b)."天"; ?>
日期a:2015-12-31 日期b:2015-10-31 兩個日期相差:61天
酷米 © All Rights Reserved.