You can use the function date() for this goal. By passing the 'w' option it returns the week number of a certain day.
First you turn 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 format "month/day/year".
So you pass this timestamp
for the function date()
with the 'w' option that returns the day number 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: http://codepad.org/QJvxuuMQ
It will print '6', because the month of November began on a Saturday, which is represented by the number 6. Sunday is represented in '0'.
By the value of the week you meant the day of the week that will be the 1st of the right month? For example, the current month of November had the 1st on a Saturday. You want him to call you "Saturday"?
– Franchesco
But if you set
$day
for the day the month begins it will return you the week.– MeuChapeu
For example for today, the result is 6 which is Friday.
– akm
I want you to give me the result for other months by changing a code to a variable $mes.
– akm