How to get the day of the week for a specific date using DateTime in PHP?

You can use the DateTime class in PHP to get the day of the week for a specific date. Here is an example:

$dateString = "2022-10-31"; // Specify your date in the format 'YYYY-MM-DD' $date = new DateTime($dateString); $dayOfWeek = $date->format('l'); echo $dayOfWeek; // Output: Monday

In this example, we create a new DateTime object using the specified date string. Then we use the format() method with the 'l' parameter to get the full day name of the week (e.g., Monday, Tuesday, etc.). Finally, we echo the day of the week.