You can use the date () function for this purpose. By passing the 'w' option it returns the number of the week of a certain day.
First you transform the date into timestamp , with the function strtotime();
. The date format will be $mes . "/01/" . date('Y')
, that is, the first day of the month $mes
of the current year. Note that the date is in the American "month / day / year" format.
Then you pass this timestamp
to the function date()
with the option 'w' that returns the number of the day of the week corresponding to that date.
function primeiroDiaDoMes($mes) {
$dia = (int) date("w", strtotime($mes . "/01/" . date('Y')));
return $dia;
}
echo primeiroDiaDoMes("11");
Example: link
You will print '6' because the month of November began on a Saturday, which is represented by the number 6. Sunday is represented at '0'.