<< View All Computer Tips

Added On: 17/01/16   |    Category: PHP5    |    Number of Views: 1586

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

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 your the proper day of the week.

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

$date = str_replace('/', '-', "19/01/2016");
$day = date('l', strtotime($date));
echo $day;