note 97406 modified in function.date by danbrown
| From: | danbrown@php.net | Date: | Mon, 19 Apr 2010 14:08:37 +0000 |
| Subject: | note 97406 modified in function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168411@lists.php.net to get a copy of this message | ||
This is a little function that returns only a working day (monday until friday). It's flexible
due to the use of a 'forbidden days' array.
I used this in a project where the delivery date can only be 10 days from now and only on a working
day (mo - fr).
<?php
function wdays($strTime = NULL){
$arrWeekend = array("6","7"); // saturday and sunday
$strTime = (is_null($strTime)) ? strtotime("+10 days") : $strTime;
if(in_array(date("N", $strTime), $arrWeekend)){
return wdays(strtotime("+1 day", $strTime));
}
else {
return $strTime;
}
}
echo date("d-m-Y",wdays());
?>
--was--
This is a little function that returns only a working day (monday until friday). It's flexible
due to the use of a 'forbidden days' array.
I used this in a project where the delivery date can only be 10 days from now and only on a working
day (mo - fr).
function wdays($strTime = NULL){
$arrWeekend = array("6","7"); // saturday and sunday
$strTime = (is_null($strTime)) ? strtotime("+10 days") : $strTime;
if(in_array(date("N", $strTime), $arrWeekend)){
return wdays(strtotime("+1 day", $strTime));
}
else {
return $strTime;
}
}
echo date("d-m-Y",wdays());
http://php.net/manual/en/function.date.php