note 32608 deleted from function.date by sniper

From: Date: Sat, 11 Oct 2003 16:54:09 +0000
Subject: note 32608 deleted from function.date by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58295@lists.php.net to get a copy of this message
Note Submitter: casey@axisintegrated.com ---- 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/

« previous php.notes (#58295) next »