求两个时间(如2002-05-09 到2002-11-30)相差的天数

admin 发表于 [PHP] 分类,标签: PHP代码 PHP自定义函数
0
#  自定义函数
function  dateMinus($date1,  $date2)  {
preg_match("/(\d+)-(\d+)-(\d+)/",  $date1,  $tmp1);
preg_match("/(\d+)-(\d+)-(\d+)/",  $date2,  $tmp2);
$timestamp1  =  mktime(0,  0,  0,  $tmp1[2],  $tmp1[3],  $tmp1[1]);
$timestamp2  =  mktime(0,  0,  0,  $tmp2[2],  $tmp2[3],  $tmp2[1]);
return  ($timestamp1-$timestamp2)  /  (60*60*24);
}  

echo  dateMinus("2002-05-09","2002-11-30");

发表我的评论