The last day of a leap year, week 53, or 1?

I have a script that processes raw CSV data and generates a report grouped by week of the year.
Which looks something like this:

//timezone is set to Europe/London
$date = new DateTime($raw['order_date']); // example: 12/31/2012

$key = $date->format('Y W'); // 2012 01

$array[$key][] = $raw['product_id'];

      

Everything worked fine until I tried to parse the data generated on New Year's Eve, for some reason the system thinks that December 31, 2012 is the week number 1 of 2012. I'm not sure if this is a bug or a feature, but the reports generated are definitely wrong.

What is the correct way to pass this problem and store the data grouped by week?

+3


source to share


3 answers


Try the following:



$key = $date->format('o W');

      

+7


source


I think the week is defined as Thursday, that is, if Thursday falls in 2013, it counts as the week of that year.



0


source


$w=(int)date('W');

$m=(int)date('n');

$w=$w==1?($m==12?53:1):($w>=51?($m==1?0:$w):$w);

$year = date('Y');

if($w==53)

{

$year=$year+1;

}

      

last year I am getting all d records as expected, but in 2016 I first select than in the April 2015 report showing that something is missing or its leap year issue is missing.

0


source







All Articles