Get value of the week that will start a month

3

I want to get the value of the week, which will start a certain month. It works for the current month, but I want it for the remaining months. This is the code I used to calculate, what day is today.

$day = date("d");
$numjour = date("N",time()-(($day-1)*3600*24));
    
asked by anonymous 28.11.2014 / 16:16

1 answer

1

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'.

    
28.11.2014 / 16:46