-1

I want to measure the number of weeks between 2 dates.

For example between 13-12-2015 and 14-12-2015 the function should return 2 weeks, because first date it's Sunday and second date it's Monday, so it's 2 different weeks.

This has to work with different year dates, and here is what I tried:

$d1= new \DateTime('2014-10-14');
$d2= new \DateTime('2015-12-15');
echo $d2->diff($d1)/7;

The result is 61, but in reality it should be 62.

Any tips?

Speedwheelftw
  • 393
  • 6
  • 19

2 Answers2

0
   echo datediff('ww', '9 July 2003', '4 March 2004', false);

datediff function you can find in following link...

Click here to see Week Difference function link

Hemant Maurya
  • 136
  • 1
  • 1
  • 14
0

I managed to do it on my own finally, here is the code:

$a1 = date('W', strtotime('2015-12-13'));
$a2 = date('Y', strtotime('2015-12-13'));

$b1 = date('W', strtotime('2015-12-14'));
$b2 = date('Y', strtotime('2015-12-14'));

echo $b2 * 52 + $b1 - $a2 * 52 - $a1 +1;

Result:

2

P.S. I don't know why everybody is spamming that is duplicate, when obviously it isn't.

Speedwheelftw
  • 393
  • 6
  • 19