3v4l.org

run code in 300+ PHP versions simultaneously
<?php $month=10; $year=2014; // Mantech $startDate = strtotime($month.'/1/'.$year); $stopDate = strtotime('last day of this month ',$startDate); if (date('D',$startDate)!='Sat'){ $startDate = strtotime('next saturday',$startDate); } if (date('D',$stopDate)!='Fri'){ $stopDate = strtotime('next friday',$stopDate); } echo (date('Y-m-d',$startDate).' - '.date('Y-m-d',$stopDate)."\n"); // If our startDate isn't a Monday, grab the previous Monday if (date('D',$startDate)!='Mon'){ $prevMonday = strtotime('last Monday',$startDate); } else { $prevMonday = $startDate; } // Format startweek as ISO8601 eg.2014W15 echo (date('Y-m-d',$prevMonday)."\n"); $beginWeek = date('o',$prevMonday).'W'.date('W',$prevMonday); echo ($beginWeek."\n"); echo (date('Y-m-d',strtotime($beginWeek))."\n"); $datediff=$stopDate-$startDate; $weeks=ceil($datediff/(60*60*24*7)); echo ($weeks."\n"); for ($i=0; $i<=$weeks; $i++){ $thisWeek = strtotime($beginWeek.' +'.$i.' weeks'); echo (date('Y-m-d',$thisWeek)."\n"); $mask = ''; for ($j=0; $j<7; $j++){ $thisDay = strtotime('+'.$j.' days',$thisWeek); echo (date('Y-m-d',$thisDay)."\n"); if ($startDate<=$thisDay or $thisDay<=$stopDate){ $mask=$mask.'1'; } else { $mask=$mask.'0'; } } echo $mask."\n"; }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.29 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
2014-10-04 - 2014-10-31 2014-09-29 2014W40 2014-09-29 4 2014-09-29 2014-09-29 2014-09-30 2014-10-01 2014-10-02 2014-10-03 2014-10-04 2014-10-05 1111111 2014-10-06 2014-10-06 2014-10-07 2014-10-08 2014-10-09 2014-10-10 2014-10-11 2014-10-12 1111111 2014-10-13 2014-10-13 2014-10-14 2014-10-15 2014-10-16 2014-10-17 2014-10-18 2014-10-19 1111111 2014-10-20 2014-10-20 2014-10-21 2014-10-22 2014-10-23 2014-10-24 2014-10-25 2014-10-26 1111111 2014-10-27 2014-10-27 2014-10-28 2014-10-29 2014-10-30 2014-10-31 2014-11-01 2014-11-02 1111111
Output for 5.1.3 - 5.1.6, 5.2.0 - 5.2.17
2014-10-04 - 1970-01-02 2014-09-29 2014W40 2014-09-29 -2335
Output for 5.1.0 - 5.1.2
2014-10-04 - 1970-01-01 2014-09-29 2014W40 2014-09-29 -2335
Output for 4.4.0 - 4.4.9, 5.0.5
2014-10-04 - 1970-01-02 2014-09-29 oW40 1970-01-01 -2335
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4
2014-10-11 - 1970-01-09 2014-10-06 oW41 1970-01-01 -2335

preferences:
262.41 ms | 402 KiB | 352 Q