3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $day = 16; //date("j"); $month = 2; //date("n"); $year = 2014; //date("Y"); if ($day > 15) { $startDay = 1; $endDay = 15; } else { $day = 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 - 7.1.0
2014-02-01 00:00:00 - 2014-02-15 23:59:59