JHacking JHacking - 1 year ago 63
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 Source

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


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

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download