note 97406 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 15 Aug 2010 18:38:51 +0000 |
| Subject: | note 97406 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171703@lists.php.net to get a copy of this message | ||
Note Submitter: robin at stylr dot nl
----
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());
?>