I'm trying to calculate the number of weeks between two dates. The code below has a result of 3 weeks. However, it is really 4 weeks. Why is it calculating incorrectly and what is the solution?
I'm curious to know why this specific code isn't working but would also like to know if there is a better way of doing it.
I'm running PHP version 7.2. Below is the code I'm using:
$HowManyWeeks = date( 'W', strtotime( 2019-04-21 23:59:00 ) ) - date( 'W', strtotime( 2019-03-25 00:00:00 ) );
The value of $HowManyWeeks should be 4 but it is displaying as 3.
Also, when I try that code at https://phpfiddle.org/ it gives an error of:
Line : 2 -- syntax error, unexpected '23' (T_LNUMBER), expecting ',' or ')'
But it displays '3' without any error when running it on my server.
Thanks,
Tim