發呆的小猪 发表于 2007-3-27 08:11
两日期相差几天如何实现?
RT,请教各位高手!
JavaEE5 发表于 2007-3-27 09:09
function DateCompare($date1, $date2) {<BR> $time1 = strtotime($date1);<BR> $time2 = strtotime($date2);<BR> return $time1 - $time2;<BR>}<BR><BR>这个是相差的秒数,再除一天的秒数应该就可以得到
發呆的小猪 发表于 2007-3-27 09:33
谢谢呀,我知道了, 用这个行不行?<BR>$t1=date('z',$time1);<BR>$t2=date('z',$time2);<BR>天数=$t2-$t1;
rainic 发表于 2007-3-27 22:16
楼上的方法.如果两个日期不在一年就不行了
rainic 发表于 2007-3-27 22:43
<?php<BR>function DateCompare($date1, $date2, $unit = "") {<BR> switch ($unit) {<BR> case 's':<BR> $dividend = 1;<BR> break;<BR> case 'i':<BR> $dividend = 60;<BR> break;<BR> case 'h':<BR> $dividend = 3600;<BR> break;<BR> case 'd':<BR> $dividend = 86400;<BR> break;<BR> default:<BR> $dividend = 86400;<BR> }<BR> $time1 = strtotime($date1);<BR> $time2 = strtotime($date2);<BR> if ($time1 && $time2)<BR> return (float)($time1 - $time2) / $dividend;<BR> return false;<BR>}<BR>echo DateCompare(date("Y-m-d H:i:s"), date("Y-2-d H:i:6"));<BR>?>
lmhllr 发表于 2007-3-29 13:12
最简单的方法,用UNIX时间戳记<BR><BR>两者一减再除以一天的秒数就可以了
發呆的小猪 发表于 2007-3-30 08:48
哦,小弟刚学习PHP,感谢大家的帮忙!!
页:
[1]