Home > front end >  Getting different weeks for my two january orders
Getting different weeks for my two january orders

Time:07-10

I am just facing issue with getting right week for my orders which I want put the numbers of orders in different weeks it into graph. The issue is that the order made in 2022-01-02 is week 52.. but order made in 2022-01-03 is week 1.. how can i achieve that the both orders will be in the same week as it is January, when every year week ends in different date in January? I hope you got my point.

PHP Example:

$date = "2022-01-02 00:00:00";
$week = (float) date("W", strtotime($date));
print $week . "\n";

$date = "2022-01-03 00:00:00";
$week = (float) date("W", strtotime($date));
print $week;

CodePudding user response:

In order to use week numbers that start on Jan 1, you need to calculate your own week numbers instead of the standard week number.

$day_of_year = date('z', strtotime($date) )   1;
$week = ceil( $day_of_year / 7 );
print $week;
  • Related