<?php
$m = 1;
$y = 2016;
echo " January 2016
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 \n\n";
echo "Original date Snaps to\n\n";
foreach (range(1, 31) as $day) {
if($day <= 9){
$day = '0'.$day;
}
/////////////////////////////
// this is the important bit
$snap = strtotime("monday this week",strtotime("$m/$day/$y"));
/////////////////////////////
echo str_pad(date('l',strtotime("$m/$day/$y")), 9, " ", STR_PAD_LEFT)," $m/$day/$y: ",date('r',$snap),"\n";
}
preferences:
41.93 ms | 402 KiB | 5 Q