- abs: documentation ( source)
- time: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
- ucfirst: documentation ( source)
<?php
function RS_GET_CLOSEST_DATE_WITH_DAYNAME($day_name)
{
$day_name = ucfirst($day_name);
if(date('l', time()) == $day_name)
{
return date("Y-m-d", time());
}
else if(abs(time()-strtotime('next '.$day_name)) < abs(time()-strtotime('last '.$day_name)))
{
return date("Y-m-d", strtotime('next '.$day_name));
}
else
{
return date("Y-m-d", strtotime('last '.$day_name));
}
}
echo RS_GET_CLOSEST_DATE_WITH_DAYNAME('Wednesday');