3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function RS_GET_DATE_WITH_DAYNAME_POSITION_FORMAT($day_name, $position = 'future', $format = 'Y-m-d H:i:s', $today_is_past = true) { $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', false);
Output for 4.3.0 - 7.1.0