3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function RS_GET_CLOSEST_DATE_WITH_DAYNAME($day_name, $format = 'Y-m-d H:i:s') { $day_name = ucfirst($day_name); if(date('l', time()) == $day_name) { return date($format, time()); } else if(abs(time()-strtotime('next '.$day_name)) < abs(time()-strtotime('last '.$day_name))) { return date($format, strtotime('next '.$day_name)); } else { return date($format, strtotime('last '.$day_name)); } } echo RS_GET_CLOSEST_DATE_WITH_DAYNAME('Monday');
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2013-11-11 00:00:00