<< More Tips   |   Added On: 17/01/16   |    Category: PHP5    |    Number of Views: 875

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

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

Linux Services

Buy Linux CDs, DVDs, USB Flash Drives from OSDisc.com

Buy Linux CDs, DVDs, USB Flash Drives from OSDisc.com

Run Windows software on Linux

Run Windows software on Linux with Crossover Office