$date = new \DateTime["now", new \DateTimeZone['Asia/Calcutta'] ];
$day = $date->format['D'];
$weekendnaame = weekedName[];
$weekid =$weekendnaame[$day];
$dayname = 0;
$weekiarray = weekendArray[$weekid];
foreach [$weekiarray as $key => $value] {
if [in_array[$value, $request->get['week_id']]]
{
$dayname = $key+1;
break;
}
}
weeknDate[$dayname],
function weeked[]{
$week = array["1"=>"Sunday", "2"=>"Monday", "3"=>"Tuesday", "4"=>"Wednesday", "5"=>"Thursday", "6"=>"Friday", "7"=>"Saturday"];
return $week;
}
function weekendArray[$day]{
$favcolor = $day;
switch [$favcolor] {
case 1:
$array = array[2,3,4,5,6,7,1];
break;
case 2:
$array = array[3,4,5,6,7,1,2];
break;
case 3:
$array = array[4,5,6,7,1,2,3];
break;
case 4:
$array = array[5,6,7,1,2,3,4];
break;
case 5:
$array = array[6,7,1,2,3,4,5];
break;
case 6:
$array = array[7,1,2,3,4,5,6];
break;
case 7:
$array = array[1,2,3,4,5,6,7];
break;
default:
$array = array[1,2,3,4,5,6,7];
}
return $array;
}
function weekedName[]{
$week = array["Sun"=>0,"Mun"=>1,"Tue"=>3,"Wed"=>4,"Thu"=>5,"Fri"=>6,"Sat"=>7];
return $week;
}
Home » PHP: Get Day Name From Date
Last updated on June 5, 2021 by
In this tutorial, we will learn how to get the day name from the date in PHP. The PHP provides very useful functions and classes by using it we can easily format
the date. Let’s just dive into it and explore it. PHP provides the date[] method which is used to format the date as we want. We can also get the day name from the date. Also, this function is useful to change any kind of date format. Let’s see simple examples.Get Day Name From Date In PHP
Example 1: Extract Day Name From Static Date
In this example, we have used the createFromFormat[] function which helps us to provide exact conversion from the specific date format else it might interpret the wrong date format and gives us the wrong output.
It is always advisable to use createFromFormat[] function while dealing with the static dates or if you changed the default date format.