第一种 方法 :
<?php function count_days($a,$b){ $a_dt=getdate($a); $b_dt=getdate($b); $a_new=mktime(12,0,0,$a_dt['mon'],$a_dt['mday'],$a_dt['year']); $b_new=mktime(12,0,0,$b_dt['mon'],$b_dt['mday'],$b_dt['year']); return round(abs($a_new-$b_new)/86400); } //今天与2012年12月25日相差多少天 $date1=strtotime(time()); $date1=strtotime('12/25/2012'); $result=count_days($date1,$date2); echo $result; ?>
PHP计算两个日期之间相差的天数两种方法
第二种方法: <?php //今天与2012年12月25日相差多少天 $Date_1=date("Y-m-d"); $Date_2="2012-12-25"; $d1=strtotime($Date_1); $d2=strtotime($Date_2); $Days=round(($d2-$d1)/3600/24); echo "今天与2012年12月25日相差".$Days."天"; ?>
查看更多关于PHP计算两个日期之间相差的天数两种方法_自学的详细内容...