note 40711 added to function.date

From: Date: Thu, 11 Mar 2004 22:23:34 +0000
Subject: note 40711 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-66690@lists.php.net to get a copy of this message
For those of you looking for something like this... This will help you solve for the number of business days between two given days. It will return a negative value if the days are reversed. function business_days( $startDay, $endDay ) ############### # Written by Mike Whitman <mike@gorillasoft.com> # # Function: formDisable() # Description: # This function calculates the number of business days between to days. # Parameters: # $startDay timestamp(double format) # $endDay timestamp(double format) # History: # ------------------------- # Editor: Change: Date: # ---------------------- # Mike Whitman Created 12/20/2002 ################# { if ( $startDay < $endDay ) { $theStart = $startDay; $theEnd = $endDay; } else { $theStart = $startDay; $theEnd = $endDay; } $daysDiff = ceil(($theEnd - $theStart)/(60*60*24)); $weeksDiff = floor($daysDiff)/7); $businessDays = 5*$weeksDiff; $extraDays = $daysDiff - ($weeksDiff*7); while ( $extraDays ) { switch ( date('w',$theEnd) ) { case 0: break; case 6: break; default: $businessDays++; break; } $theEnd -= (60*60*24); $extraDays--; } return $businessDays; } Thanks to all of those who contribute, I hope this helps someone. -M ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40711 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40711&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40711&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66690) next »