3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //echo date('r', strtotime('last sunday', strtotime('6 April 1991'))); function align_timestamp_to($stamp, $unit, $past){ // timestamp, unit string, start/end static $modes = array( 'week' => 'last monday', 'month' => 'first day of month', ); // TODO error out if unknown $unit $offset = $modes[$unit]; if($past == 'end')$offset = '+1 '.$unit.' '.$offset; $new = strtotime($offset, $stamp); } foreach(array( array(strtotime('4 Apr 2012'), 'week', 'start'), array(strtotime('4 Apr 2012'), 'week', 'end'), ) as $test)echo date('r', $test[0]).' aligned '.$test[2].' of '.$test[1].' yields '.date('r', align_timestamp_to($test[0], $test[1], $test[2])).'<br/>';
Output for 4.3.11 - 4.4.9, 5.0.4 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Wed, 04 Apr 2012 00:00:00 +0200 aligned start of week yields Thu, 01 Jan 1970 01:00:00 +0100<br/>Wed, 04 Apr 2012 00:00:00 +0200 aligned end of week yields Thu, 01 Jan 1970 01:00:00 +0100<br/>
Output for 4.3.0 - 4.3.10, 5.0.0 - 5.0.3
Wed, 4 Apr 2012 00:00:00 +0200 aligned start of week yields Thu, 1 Jan 1970 01:00:00 +0100<br/>Wed, 4 Apr 2012 00:00:00 +0200 aligned end of week yields Thu, 1 Jan 1970 01:00:00 +0100<br/>