3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $month=9; $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 and $thisDay<=$stopDate){ $mask=$mask.'1'; } else { $mask=$mask.'0'; } } echo $mask."\n"; }
Output for 5.3.0 - 7.1.0
2014-09-06 - 2014-10-03 2014-09-01 2014W36 2014-09-01 4 2014-09-01 2014-09-01 2014-09-02 2014-09-03 2014-09-04 2014-09-05 2014-09-06 2014-09-07 0000011 2014-09-08 2014-09-08 2014-09-09 2014-09-10 2014-09-11 2014-09-12 2014-09-13 2014-09-14 1111111 2014-09-15 2014-09-15 2014-09-16 2014-09-17 2014-09-18 2014-09-19 2014-09-20 2014-09-21 1111111 2014-09-22 2014-09-22 2014-09-23 2014-09-24 2014-09-25 2014-09-26 2014-09-27 2014-09-28 1111111 2014-09-29 2014-09-29 2014-09-30 2014-10-01 2014-10-02 2014-10-03 2014-10-04 2014-10-05 1111100
Output for 5.1.3 - 5.2.17
2014-09-06 - 1970-01-02 2014-09-01 2014W36 2014-09-01 -2331
Output for 5.1.0 - 5.1.2
2014-09-06 - 1970-01-01 2014-09-01 2014W36 2014-09-01 -2331
Output for 4.4.0 - 4.4.9, 5.0.5
2014-09-06 - 1970-01-02 2014-09-01 oW36 1970-01-01 -2331
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4
2014-09-13 - 1970-01-09 2014-09-08 oW37 1970-01-01 -2331