禹顺生态建设有限公司网站,长沙设计网站效果,企业网站seo优化,装潢设计培训中心你的位置:问答吧- PHP基础- 问题详情怎么样计算2个日期之间相差几周如题如果2个日期在同一年中的话可以通过date(W,unix时间戳)来计算但特别麻烦的就是2个日期不是在同一年中#xff0c;可能2个日期相差几年请高手指教作者: gengle53022发布时间: 2007-04…你的位置:问答吧- PHP基础- 问题详情怎么样计算2个日期之间相差几周如题如果2个日期在同一年中的话可以通过date(W,unix时间戳)来计算但特别麻烦的就是2个日期不是在同一年中可能2个日期相差几年请高手指教作者: gengle53022发布时间: 2007-04-18可以先算相差多少天 然后再算有多少个周啊作者: 只爱一个人发布时间: 2007-04-18$year_f2300;$year_nidate(Y);if(!$year_n0)$count_r($year_f-($year_n (4-($year_n % 4))))/4;else$count_r($year_f-$year_n)/41;$week(((($year_f-$year_n)1)*365)$$count_r)/7;echo $count_r;?不知道这样行吧作者: 真爱有限发布时间: 2007-04-18CODE:[Copy to clipboard]//按标准时间计算$time1 2006-1-1 15:14:12; //时间1$time2 date(Y-m-d H:i:s); //时间2echo (dateDiff(D,$time1,$time2)). weeks;function dateDiff($date_part,$start_date,$end_date){$starttimestamp strtotime($start_date);if (-1 $starttimestamp) {return false;}$endtimestamp strtotime($end_date);if (-1 $endtimestamp) {return false;}switch(strtoupper(trim($date_part))){case D://按天计算,返回天数/7$starttimestamp strtotime(date(Y-m-d 00:00:00, $starttimestamp));$endtimestamp strtotime(date(Y-m-d 00:00:00, $endtimestamp));#return intval((($endtimestamp - $starttimestamp) / (60*60*24)));//返回天数return intval((($endtimestamp - $starttimestamp) / (60*60*24))/7);//返回周/7break;default:return FALSE;}}作者: chinahtml发布时间: 2007-04-18先转化为时间戳再求差值。LS的if (-1 $starttimestamp) {return false;}这一步是什么作用作者: coolsail发布时间: 2007-04-18strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳作者: chinahtml发布时间: 2007-04-18查了下手册,strtotime在PHP 5.1.0 之前此函数在失败时返回 -1,5.1.0之后 失败时返回 FALSE不再是 -1。作者: coolsail发布时间: 2007-04-19