note 97553 added to function.strtotime
| From: | A dot Lepedev+php at alepe dot com | Date: | Mon, 26 Apr 2010 03:11:03 +0000 |
| Subject: | note 97553 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168633@lists.php.net to get a copy of this message | ||
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"));
?>
----
Server IP: 69.147.83.197
Probable Submitter: 211.6.179.194
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/97553
Del: integrated -- https://master.php.net/note/delete/97553/integrated
Del: useless -- https://master.php.net/note/delete/97553/useless
Del: bad code -- https://master.php.net/note/delete/97553/bad+code
Del: spam -- https://master.php.net/note/delete/97553/spam
Del: non-english -- https://master.php.net/note/delete/97553/non-english
Del: in docs -- https://master.php.net/note/delete/97553/in+docs
Del: other reasons-- https://master.php.net/note/delete/97553
Reject -- https://master.php.net/note/reject/97553
Search -- https://master.php.net/manage/user-notes.php