Чтобы получить с воскресенья по субботу с числового дня недели 0 до 6 :
//For example, our target numeric day is 0 (Sunday):
$numericDay = 0; //assuming current date('w')==0 and date('D')=='Sun';
Solution-1: Использование встроенной в PHP функции jddayofweek () , которая начинается с Monday
, тогда как date('w')
начинается с Sunday
:
jddayofweek($numericDay-1, 1); //returns 'Sun', here decreasing by '-1' is important(!)
//jddayofweek(0, 1); //returns 'Mon';
//jddayofweek(0, 2); //returns 'Monday';
Решение-2: Использование трюка (!):
date('D', strtotime("Sunday +{$numericDay} days")); //returns 'Sun';
//date('l', strtotime("Sunday +{$numericDay} days")); //returns 'Sunday';