benphp Posted March 26, 2010 Share Posted March 26, 2010 Alright - I spent most of the day wrestling with this one. I have 6 shifts of people that rotate through our training throughout the year. I need to list them by week of the year, and the shifts will usually start the year NOT on 1. For example: Week 1 - Week of Jan 04 = Shift 5 Week 2 - Week of Jan 11 = Shift 6 Week 3 - Week of Jan 18 = Shift 1 Week 4 - Week of Jan 25 = Shift 2 Week 5 - Week of Feb 01 = Shift 3 Week 6 - Week of Feb 08 = Shift 4 Week 7 - Week of Feb 16 = Shift 5 Week 8 - Week of Feb 22 = Shift 6 Week 9 - Week of Mar 01 = Shift 1 ...etc I was able to find the week of the year and the mondays, but I'm having a hard time matching the shifts with these dates. <?php $weekOfYear = "$year-$month-$day"; $weekOfYear = strftime("%W", strtotime("$weekOfYear")); $weekOfYear = $weekOfYear * 1; /////////// ///FIND MONDAY $todayIsMonday = ""; $findMonday = date('D', mktime(0,0,0,$month,$day,$year)); if($findMonday == "Mon") { $todayIsMonday = "<a href=\"events_shift.php?y=$year&m=$month&d=$day\">Shift $IneedToFindTheShiftNum</a><br />"; } ///FIND MONDAY ?> Quote Link to comment https://forums.phpfreaks.com/topic/196664-help-with-calendar-weeks/ Share on other sites More sharing options...
Psycho Posted March 27, 2010 Share Posted March 27, 2010 Just set the three variables in the function: The year, the shift that will do training on the first week, and the number of total shifts <?php function getShiftForWeek($weekNo) { $output = array(); $initialYear = 2010; $firstShift = 5; $totalShifts = 6; $firstMonday = strtotime("first monday jan $initialYear"); $output['week'] = $weekNo; $output['timestamp'] = $firstMonday + (($weekNo-1) * 604800); $output['monthDay'] = date('M d', $output['timestamp']); $output['shift'] = (($weekNo + $firstShift - 1) % $totalShifts); if ($output['shift']==0) { $output['shift'] = $totalShifts; } return $output; } for ($week=1; $week<15; $week++) { $data = getShiftForWeek($week); echo "Week {$data['week']} - Week of {$data['monthDay']} = Shift {$data['shift']}<br />\n"; } ?> Output: Week 1 - Week of Jan 04 = Shift 5 Week 2 - Week of Jan 11 = Shift 6 Week 3 - Week of Jan 18 = Shift 1 Week 4 - Week of Jan 25 = Shift 2 Week 5 - Week of Feb 01 = Shift 3 Week 6 - Week of Feb 08 = Shift 4 Week 7 - Week of Feb 15 = Shift 5 Week 8 - Week of Feb 22 = Shift 6 Week 9 - Week of Mar 01 = Shift 1 Week 10 - Week of Mar 08 = Shift 2 Week 11 - Week of Mar 15 = Shift 3 Week 12 - Week of Mar 22 = Shift 4 Week 13 - Week of Mar 29 = Shift 5 Week 14 - Week of Apr 05 = Shift 6 Quote Link to comment https://forums.phpfreaks.com/topic/196664-help-with-calendar-weeks/#findComment-1032552 Share on other sites More sharing options...
benphp Posted March 29, 2010 Author Share Posted March 29, 2010 THANK YOU! I love this site. Quote Link to comment https://forums.phpfreaks.com/topic/196664-help-with-calendar-weeks/#findComment-1033621 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.