note 97553 deleted from function.strtotime by derick

From: Date: Sun, 14 Dec 2014 11:31:01 +0000
Subject: note 97553 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201155@lists.php.net to get a copy of this message
Note Submitter: A dot Lepe dev+php at alepe dot com ---- This is a quick function to calculate the "working days" within a period of one year. "Working days" are those without weekends and without the holidays specified in the $holiday array. I left for the reader its implementation for more than 1 year. <?php /* * Author: Alberto Lepe * Calculates the working days from today to an specific date. * NOTE: counting starts from today * @pararm to_date: timestamp */ function get_working_days($to_date) { $holidays = array( 1 => array(10), //2011 ... 2 => array(11), 3 => array(21), //... 2011 4 => array(29,30), //2010 ... 5 => array(3,4,5), 6 => array(), 7 => array(19), 8 => array(11,12,13), 9 => array(20,23), 10 => array(11), 11 => array(3,23), 12 => array(23) //... 2010 ); for($to_date, $w = 0, $i = 0, $x = time(); $x < $to_date; $i++, $x = strtotime("+$i day")) { if(date("N",$x) < 6 &! in_array(date("j",$x),$holidays[date("n",$x)])) $w++; } return $w; } //Usage: echo get_working_days(strtotime("2011-01-08")); ?>

« previous php.notes (#201155) next »