note 32608 added to function.date

From: Date: Mon, 02 Jun 2003 21:30:10 +0000
Subject: note 32608 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-49587@lists.php.net to get a copy of this message
I needed a function to calculate the shipping date of a product based upon a variable lead time. Thanks to nuroslam at defendem dot com for the example above that got me started. Here is what I came up with, hope it helps someone. function lead_time($lead) { # Calculate Lead Time in Business Days # This function calculates the estimated shipping date # based upon the passed lead time. # Get todays date $today = date("Y-m-d"); # Day of Week necessary to detect weekend landing $day = date("w"); # Calc weeks & remainder days $wks = intval($lead / 5); $rdays = $lead - ($wks * 5); #print "Your lead time is $lead which requires $wks week(s) and $rdays day(s).\n"; # Check for landing on the weekend if ($rdays + $day > 5) { # Compensate for the weekend $rdays += 2; } # Total days needed for lead $total_lead = ($wks * 7) + $rdays; # Lead Time Date Calculation $newday = date("l, Y-m-d", strtotime("$today + $total_lead days")); return $newday; } // End Function lead_time($lead) USAGE: I used a quick for loop for error checking: for ($i=1; $i<=40; $i++) { $newday = lead_time($i); print "A lead time of $i gives a shipping date of: $newday\n"; } Best Regards, Casey Dinsmore http://www.axisintegrated.com/ ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32608 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32608&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32608&report=yes

« previous php.notes (#49587) next »