Category: PHP7

Added: 17th of January 2016

Updated On: 28th of October 2020

Viewed: 3,720 times


This article was updated and rechecked on 28th of October 2020

Get the day of the week for a specified date using PHP7

One thing I noted, you will get varying results if you try to get the day of the week from a specified date in PHP if you submit your date in the following format dd/mm/yy.

What you need to do is replace / with - in your date using the str_replace function, convert the date to a unix timestamp, then use the date function with l switch, which will give you the proper day of the week.

Copy and paste the code below. The code will display Wednesday

<?php
$date = str_replace('/', '-', "28/10/2020");
$day = date('l', strtotime($date));
echo $day;
?>


If you just wanted to get the day of the week at anytime, we can use now
echo $day = date('l', strtotime(now));