note 87283 modified in function.date by danbrown

From: Date: Thu, 27 Nov 2008 23:11:53 +0000
Subject: note 87283 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147054@lists.php.net to get a copy of this message
Reverse of getWorkingDays() function. <?php function getTargetWorkingDate($startDate, $days, $holidays = null) { $the_first_day_of_week = date("N",strtotime($startDate)); if($the_first_day_of_week == 6) $b_extra+=2; if($the_first_day_of_week == 7) $b_extra++; $startDate = getdate((($b_extra) * 86400) + strtotime($startDate)); $startDate = $startDate['year'] . "-" . $startDate['mon'] . "-" . $startDate['mday']; $no_weeks = floor($days / 5); $extra_days = $no_weeks * 2; $endDate = getdate((($days+$extra_days) * 86400) + strtotime($startDate)); $endDate = $endDate['year'] . "-" . $endDate['mon'] . "-" . $endDate['mday']; if($holidays) { foreach($holidays as $holiday){ $time_stamp = strtotime($holiday); if (strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate) && date("N",$time_stamp) != 6 && date("N",$time_stamp) != 7) $extra_days++; } } $endDate = getdate((($days+$extra_days) * 86400) + strtotime($startDate)); $endDate = $endDate['year'] . "-" . $endDate['mon'] . "-" . $endDate['mday']; $the_last_day_of_week = date("N",strtotime($endDate)); if($the_last_day_of_week == 6) $e_extra+=2; if($the_last_day_of_week == 7) $e_extra++; $endDate = getdate((($e_extra) * 86400) + strtotime($endDate)); $endDate = $endDate['year'] . "-" . $endDate['mon'] . "-" . $endDate['mday']; return $endDate; } ?> --was-- re: june at overlie dot no Reverse of getWorkingDays() function. function getTargetWorkingDate($startDate, $days, $holidays = null) { $the_first_day_of_week = date("N",strtotime($startDate)); if($the_first_day_of_week == 6) $b_extra+=2; if($the_first_day_of_week == 7) $b_extra++; $startDate = getdate((($b_extra) * 86400) + strtotime($startDate)); $startDate = $startDate['year'] . "-" . $startDate['mon'] . "-" . $startDate['mday']; $no_weeks = floor($days / 5); $extra_days = $no_weeks * 2; $endDate = getdate((($days+$extra_days) * 86400) + strtotime($startDate)); $endDate = $endDate['year'] . "-" . $endDate['mon'] . "-" . $endDate['mday']; if($holidays) { foreach($holidays as $holiday){ $time_stamp = strtotime($holiday); if (strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate) && date("N",$time_stamp) != 6 && date("N",$time_stamp) != 7) $extra_days++; } } $endDate = getdate((($days+$extra_days) * 86400) + strtotime($startDate)); $endDate = $endDate['year'] . "-" . $endDate['mon'] . "-" . $endDate['mday']; $the_last_day_of_week = date("N",strtotime($endDate)); if($the_last_day_of_week == 6) $e_extra+=2; if($the_last_day_of_week == 7) $e_extra++; $endDate = getdate((($e_extra) * 86400) + strtotime($endDate)); $endDate = $endDate['year'] . "-" . $endDate['mon'] . "-" . $endDate['mday']; return $endDate; } http://php.net/manual/en/function.date.php

« previous php.notes (#147054) next »