RE: [PHP] workdays - CODE

From: Date: Thu, 16 Nov 2000 01:00:43 +0000
Subject: RE: [PHP] workdays - CODE
Groups: php.general 
Request: Send a blank email to php-general+get-25564@lists.php.net to get a copy of this message
Finally I wrote this code that shows the difference between two dates without Saturdays and Sundays... Additions/corrections will be appreciated... (i would like to include holidays feature) Regards <? // Code by elbuenchubi // elchubi@hotmail.com // gpled // define dates $month1=11; $day1=30; $year1=2000; $month2=12; $day2=6; $year2=2000; $days=0; // get timestamp $date1=mktime($hour1,$minute1,$second1,$month1,$day1,$year1); $date2=mktime($hour2,$minute2,$second2,$month2,$day2,$year2); // get week day number $dayofweek1=date(w,$date1); $dayofweek2=date(w,$date2); // calculates the weeks difference between the dates $diff_in_secs=$date2 - $date1; $diff_in_days=$diff_in_secs / 86400; $diff_in_weeks=$diff_in_days /7; $diff_in_weeks=floor($diff_in_weeks); // add remaining days if ($dayofweek1<$dayofweek2) { $days=$dayofweek2-$dayofweek1; if ($dayofweek2==6) $days=$days-1; } if ($dayofweek1>$dayofweek2) { if ($dayofweek1<>'6') { $days=5-$dayofweek1+$dayofweek2; } else { $days=$dayofweek2; } } // calculate days difference without Saturdays and Sundays $workdays=($diff_in_weeks*5)+($days); // get Fiscalweek number (doesn't afect the code purpose) $fiscalweek1=strftime ("%V", $date1); $fiscalweek2=strftime ("%V", $date2); // show results echo "=".$diff_in_days." dias de diferencia, <br>"; echo "=".$diff_in_weeks." semanas <br>"; echo "=".$workdays." días laborales, <br>"; echo "entre el ".date('m/d/Y',$date1)." <i>(FW".$fiscalweek1.")</i> y el ".date('m/d/Y',$date2)." <i>(FW".$fiscalweek2.")</i><br>"; ?> > -----Original Message----- > From: Richard Lynch [SMTP:richard@zend.com] > Sent: Tuesday, November 14, 2000 4:06 PM > To: php-general@lists.php.net > Subject: Re: [PHP] workdays > > > I need a function to calculate the difference, in days, between to > > given dates BUT taking only the work days. Similar to the "networkdays" > in > > excel. > > Has anybody know how to do this?? > > I'm pretty sure somebody posted some sample code to do this somewhere... > > Either here or in one of the code archives linked from > http://php.net/links.php > > You should be able to do it fairly easily, actually, by just counting the > total days and weeks and working out if either day is a weekend etc. Of > course, holidays are also going to be tricky, if you need to take those > into > account. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#25564) next »