3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $day = 1; //date("j"); $month = 7; //date("n"); $year = 2014; //date("Y"); if ($day > 15) { $startDay = 1; $endDay = 15; } else { $startDay = 16; if ($month == 1) { $month = 12; $year--; } else { $month--; } $endDay = date("t", strtotime($year."-".$month."-".$day)); } $rangeStart = date("Y-m-d 00:00:00", strtotime($year."-".$month."-".$startDay)); $rangeEnd = date("Y-m-d 23:59:59", strtotime($year."-".$month."-".$endDay)); echo "$rangeStart - $rangeEnd"; ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2014-06-16 00:00:00 - 2014-06-30 23:59:59