3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function RS_GET_DATE_WITH_DAYNAME_POSITION_FORMAT($day_name, $position = 'future', $today_is_past = true, $format = 'Y-m-d H:i:s') { //$day = ucfirst($day_name); $today_name = date('l', time()); $today = date('Y-m-d 00:00:00', time()); // Je force l'heure à minuit sinon dans certain cas nous sommes déjà dans le future alors qu'on est aujourd'hui $next = date($format, strtotime('next '.$day_name)); $last = date($format, strtotime('last '.$day_name)); if($position == 'future') { if($today_name != $day_name) { return $next; } else { if($today_is_past) return $next; else return $today; } } else { if($today_name != $day_name) { return $last; } else { if($today_is_past) return $today; else return $last; } } } echo RS_GET_DATE_WITH_DAYNAME_POSITION_FORMAT('Wednesday', 'future', true);
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4, 5.1.0 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2013-11-20 00:00:00
Output for 4.4.0 - 4.4.9, 5.0.5
2013-11-13 00:00:00