note 59091 deleted from function.date by derick

From: Date: Sun, 11 Jun 2006 11:41:21 +0000
Subject: note 59091 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114242@lists.php.net to get a copy of this message
Note Submitter: chetan at jethwa dot org ---- function for calculating N working days from a date. <?php /* $date - date (dd/mm/yyyy) $n - number of days $t - resulting timestamp */ function getNthWorkingDay($date,$n,&$t) { $arr = array(); list($day,$month,$year) = explode("/",$date); $ts = mktime(0,0,0,$month,$day,$year); for($i = 1; $i <= $n; $i++) { $_ts = mktime(0,0,0,$month,$day + $i,$year); $arr[$i - 1]["d"] = date("w",$_ts); $arr[$i - 1]["ts"] = $_ts; } $working_days = array(); $j = 0; for($i = 1; $i <= $n; $i++) { if($arr[$i - 1]["d"] != 6 AND $arr[$i - 1]["d"] != 0) { $working_days[$j]["d"] = $arr[$i - 1]["d"]; $working_days[$j]["ts"] = $arr[$i - 1]["ts"]; $j++; } } if(sizeOf($working_days) >= $n) { $t = $working_days[sizeOf($working_days) - 1]["ts"]; } else { $_n = $n - sizeOf($working_days); getNthWorkingDay(date("d/m/Y",$arr[$n-1]["ts"]),$_n,$t); } } ?>

« previous php.notes (#114242) next »