5
I need to check the number of the week and count how many days there are each week of the month.
With this code, I know the number of the week in the month (not the week of the year):
function weekOfMonth($date) {
// estract date parts
list($y, $m, $d) = explode('-', date('Y-m-d', strtotime($date)));
// current week, min 1
$w = 1;
// for each day since the start of the month
for ($i = 1; $i <= $d; ++$i) {
// if that day was a sunday and is not the first day of month
if ($i > 1 && date('w', strtotime("$y-$m-$i")) == 0) {
// increment current week
++$w;
}
}
// now return
return $w;
}
Now I plan to count how many days each week number has (September 2017):
d s t q q s s
01 02 = semana 1 -> 2 dias
03 04 05 06 07 08 09 = semana 2 -> 7 dias
10 11 12 13 14 15 16 = semana 3 -> 7 dias
17 18 19 20 21 22 23 = semana 4 -> 7 dias
24 25 26 27 28 29 30 = semana 5 -> 7 dias
Because they vote negative, is there something wrong, that I can fix? or is wrong?
– novic