snowman2344 Posted November 27, 2007 Share Posted November 27, 2007 I need to calculate the following schedule in php. What I need out of the script is what shift is working “today” E.G. $shift = d;. There are 4 shifts working 24hr days starting at 7 am. The days rotate on 28 day cycles. E.G. ‘C shift’ is working on July 1 (Sunday) the next Sunday they work is the 29th. I found some code that works with 3 shifts on a different cycle but I have 4 shifts. $referencePoint = mktime(7, 0, 0, 9, 11, 2004); // Sept 11, 2004 at 7AM started an A Shift. $now = time(); // Next we need to know how many seconds since the start of the last A Shift. // First we compute how many 3 days cycles since the reference point then // subtract that number. $difference = ($now - $referencePoint); $cycles = floor($difference / (60 * 60 * 24 * 3)); $sinceReference = ($difference - ($cycles * 60 * 60 * 24 * 3)); if ($sinceReference < 60 * 60 * 25) { // Before the start of the 25th hour it's A Shift. $shift = "A"; } elseif ($sinceReference < 60 * 60 * 49) { // Else before the start of the 49th hour it's B Shift. $shift = "B"; } else { $shift = "C"; // Else it's C Shift. } Quote Link to comment Share on other sites More sharing options...
sasa Posted November 27, 2007 Share Posted November 27, 2007 try <?php $start_date = '7/1/2007'; $shift_cycle = array('C', 'A','B','C','A','D','C','D', 'B','C','D','B','A','D','A', 'C','D','A','C','B','A','B', 'D','A','B','D','C','B'); $today = date('m/d/y'); //$today = '12/29/2007'; //for testing echo 'Shift is ', $s = $shift_cycle[((strtotime($today) - strtotime($start_date))/(86400))%28]; ?> Quote Link to comment Share on other sites More sharing options...
snowman2344 Posted November 28, 2007 Author Share Posted November 28, 2007 That seems to work great thanks Quote Link to comment Share on other sites More sharing options...
snowman2344 Posted November 29, 2007 Author Share Posted November 29, 2007 Just so i can learn from this what does the %28 do?? ??? Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 29, 2007 Share Posted November 29, 2007 % is modulo (remainer) Quote Link to comment Share on other sites More sharing options...
snowman2344 Posted November 29, 2007 Author Share Posted November 29, 2007 Guess is missed that in junior school.?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.