PHP week number again

We use the ISO 8601 standard to show week numbers here in Sweden. Most people seem to confuse this standard, which may be in the 1st week last year. I know about it.

I have another weird problem, every Monday date shows the wrong week number. To my knowledge, weeks should start on Mondays in accordance with this standard and the PHP manual. Am I missing something obvious? I am using PHP5.3.3. Thanks in advance!

$week = date('W', strtotime('2011-01-24')); //gives $week = 03

$week = date('W', strtotime('2011-01-25')); //gives $week = 04 correct!

According to my calendar 2011-01-24 should be week 4

enter image description here

+3
source share
1 answer

This is most likely a time zone problem.

Try again, explicitly setting the time zone offset:

$week = date('W', strtotime('2011-01-24T00:00:01+0200')); // 03 - incorrect behavior
$week = date('W', strtotime('2011-01-24T00:00:01+0000')); // 04 - correct behavior!
0
source

Source: https://habr.com/ru/post/1791441/


All Articles