JHacking JHacking - 1 month ago 13
PHP Question

Get a month's first day in a string(Monday,Tuesday) in php

I've been trying to get the first day in a string of a month.
I have two variables:

$year = 2016;
$month = "November";


And I want to get the first day of November of 2016(that is Tuesday).
I have tried

$string = "$year-$month-01";
echo date("l",strtotime($string));


And also

$string = "$year-$month-01";
echo date("l",$string);


Please help me!

Answer

You're forgetting about UTC timezone offsets relative to your location. Minimal fix for your code is to use gmdate

<?php

$year = 2016;
$month = "November";

$string = "$year-$month-01";
echo gmdate("l",strtotime($string));

Tuesday