Calculating week numbers in PHP using Year, is that a mistake?

This is strange, I do not know if this is a mistake, but please, someone will try.

Do it in php

echo date("YW",strtotime("2014W05 -1 weeks")); 

The result will be 2014-04, right? YEAR NumberWeek. No problem at all. But now try the following:

 echo date("YW",strtotime("2014W02 -1 weeks")); 

Why is it 2013-01, why 2013? What's wrong? It should be 2014-01, right?

What am I doing wrong? This is mistake?

My PHP Version: 5.4.22

+7
php
source share
1 answer
 Y is year from the date o is ISO-8601 year number 

So if you do it like

 echo date("oW",strtotime("2014W05 -1 weeks"))."<br/>"; echo date("oW",strtotime("2014W02 -1 weeks")); 

You'll get

 2014-04 2014-01 

Edit by Jasper

Since the date is a moment, not a week, you request a week and get the first moment of this week. According to standards, the week number is based on what year Thursday is. In this case, the week number is 1, but the date is still in 2013.

+10
source share

All Articles