简体   繁体   中英

Last day of the leap year, week 53 or 1?

I have a script that process raw CSV data and generate 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 was working fine until I tried to parse data generated over new year eve, for some reason system believes that 31 December 2012 is week number 1 of year 2012. I'm not sure is it bug or a feature, but produced reports are definitely wrong.

What is a correct way of passing this issue and keeping data grouped by weeks?

试试这个:

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

我认为本周定义为星期四,这意味着如果星期四在2013年下降,那么它将被计为当年的一周。

$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;

}

past year i am getting all d records properly but in 2016 april first select than I got april 2015 report show any thing missing or its leap year problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM