prince198 Posted August 4, 2008 Share Posted August 4, 2008 hi evrybody i found this scripts that calculate diference between 2 dates not includind sunday and holidays function getWorkingDays($startDate,$endDate,$holidays){ //The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24 //We add one to inlude both dates in the interval. $days = (strtotime($endDate) - strtotime($startDate)) / 86400 + 1; $no_full_weeks = floor($days / 7); $no_remaining_days = fmod($days, 7); //It will return 1 if it's Monday,.. ,7 for Sunday $the_first_day_of_week = date("N",strtotime($startDate)); $the_last_day_of_week = date("N",strtotime($endDate)); //---->The two can be equal in leap years when february has 29 days, the equal sign is added here //In the first case the whole interval is within a week, in the second case the interval falls in two weeks. if ($the_first_day_of_week <= $the_last_day_of_week){ if ($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week) $no_remaining_days--; if ($the_first_day_of_week <= 7 && 7 <= $the_last_day_of_week) $no_remaining_days--; } else{ if ($the_first_day_of_week <= 6) $no_remaining_days--; //In the case when the interval falls in two weeks, there will be a Sunday for sure $no_remaining_days--; } //The no. of business days is: (number of weeks between the two dates) * (5 working days) + the remainder //---->february in none leap years gave a remainder of 0 but still calculated weekends between first and last day, this is one way to fix it $workingDays = $no_full_weeks * 5; if ($no_remaining_days > 0 ) { $workingDays += $no_remaining_days; } //We subtract the holidays foreach($holidays as $holiday){ $time_stamp=strtotime($holiday); //If the holiday doesn't fall in weekend if (strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate) && date("N",$time_stamp) != 6 && date("N",$time_stamp) != 7) $workingDays--; } return $workingDays; } //Example: $holidays=array("2006-12-25","2006-12-26","2008-01-01"); echo getWorkingDays("2008-01-01","2008-01-31",$holidays); so as yu see i wil have result 22 days but i'm looking for is display resulut like this week 1: 3 days; week 2: 5days; week 3; 5 days; week 4 5 days; week 5 4 days; and i can't see how i use this functions if i have many days for exemple start days | end days 2008-01-01 2008-01-31 2008-01-05 2008-02-02 thank for helping Link to comment https://forums.phpfreaks.com/topic/118084-caclculate-difference-between-two-date-group-by-week/ Share on other sites More sharing options...
prince198 Posted August 4, 2008 Author Share Posted August 4, 2008 no body unterstand the problem???????????? Link to comment https://forums.phpfreaks.com/topic/118084-caclculate-difference-between-two-date-group-by-week/#findComment-607546 Share on other sites More sharing options...
prince198 Posted August 4, 2008 Author Share Posted August 4, 2008 ??? ??? ??? i feel that anyperson unterstand what i'm looking for Link to comment https://forums.phpfreaks.com/topic/118084-caclculate-difference-between-two-date-group-by-week/#findComment-607604 Share on other sites More sharing options...
prince198 Posted August 4, 2008 Author Share Posted August 4, 2008 nobody know how calculate by week?????? Link to comment https://forums.phpfreaks.com/topic/118084-caclculate-difference-between-two-date-group-by-week/#findComment-607928 Share on other sites More sharing options...
prince198 Posted August 5, 2008 Author Share Posted August 5, 2008 i give up :-\ :-\ i can't find solution so, i think that there is not solution Link to comment https://forums.phpfreaks.com/topic/118084-caclculate-difference-between-two-date-group-by-week/#findComment-608366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.