RE: [PHP] workdays - CODE

From: Date: Fri, 17 Nov 2000 19:49:42 +0000
Subject: RE: [PHP] workdays - CODE
Groups: php.general 
Request: Send a blank email to php-general+get-25953@lists.php.net to get a copy of this message
This is the function for workday (in Excel) by the moment, it only works for negative $days (that's what i needed). Regards function workday($date1,$days) { if ($days<>0) $ff0=(abs($days)/$days); // return the workday $ff1=ceil(abs($days)); $ff2=(abs($ff1)/5); $ff3=floor($ff2*7); $ff7=($ff3)*$ff0; // get time stamp $day=date(d,$date1); $month=date(m,$date1); $year=date(Y,$date1); $ff8=mktime(0,0,0,$month,$day+($ff7),$year); // Correct if final date is Saturday or Sunday $dayofweek1=date(w,$date1); $dayofweek2=date(w,$ff8); if ($dayofweek2>$dayofweek1 and $dayofweek1<>0) $ffc=(1*$ff0); if ($dayofweek2==6 and $dayofweek1>0 and $dayofweek1<3) $ffc=$ffc+(1*$ff0); if ($dayofweek1==6 and $dayofweek2>0 and $dayofweek2<3) $ffc=-(1*$ff0); if ($dayofweek2==6 and $dayofweek1==6) $ffc=-(2*$ff0); $ff8=mktime(0,0,0,$month,$day+($ff7)+($ffc),$year); $dayofweek3=date(w,$ff8); if ($dayofweek3==0 and $dayofweek1<>0) $ffb=(2*$ff0); if ($dayofweek3==6) $ffb=(1*$ff0); if ($dayofweek3==0 and $dayofweek1==0) $ffb=-(1*$ff0); if ($dayofweek3==5 and $dayofweek1==0) $ffb=(1*$ff0); if ($dayofweek2==0 and $dayofweek1==4) $ffb=-(1*$ff0); if ($dayofweek2<2 and $dayofweek1==5) $ffb=-(1*$ff0); $ff8=mktime(0,0,0,$month,$day+($ff7)+($ffc)+($ffb),$year); // Format date $ff11=strtoupper(date("d-M-y", $ff8)); return($ff11); }

« previous php.general (#25953) next »