3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function closestDate($day){ $day = ucfirst($day); if(date('l', time()) == $day) return date("Y-m-d", time()); else if(abs(time()-strtotime('next '.$day)) < abs(time()-strtotime('last '.$day))) return date("Y-m-d", strtotime('next '.$day)); else return date("Y-m-d", strtotime('last '.$day)); } echo closestDate('Monday');
Output for 4.3.0 - 7.1.0
2013-11-11