note 102372 deleted from function.strtotime by derick

From: Date: Sun, 03 Nov 2013 15:19:00 +0000
Subject: note 102372 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197402@lists.php.net to get a copy of this message
Note Submitter: nick at optixsolutions dot co dot uk ---- Function to add days (excluding specified days/dates) <?php function addDays($timestamp, $days, $skipdays=NULL, $skipdates=NULL){ // $skipdays: array (Monday-Sunday) eg. array("Saturday","Sunday") // $skipdates: array (YYYY-mm-dd) eg. array("2012-05-02","2015-08-01"); $i = 1; while($days >= $i){ $timestamp = strtotime("+1 day" ,$timestamp); if(in_array(date("l",$timestamp), $skipdays) || in_array(date("Y-m-d",$timestamp), $skipdates)){ $days++; } $i++; } return $timestamp; } ?> I use this in combination with the calculateBankHolidays function in the notes here: http://php.net/manual/en/ref.calendar.php to skip working days in the UK: <?php $skipdays = array("Saturday","Sunday"); $skipdates = array_merge(calculateBankHolidays(date("Y")), calculateBankHolidays(date("Y", strtotime("+1 year")))); $ts = addDays(strtotime("now"), 1, $skipdays, $skipdates); ?>

« previous php.notes (#197402) next »