Mlungisi Mlungisi - 21 days ago 5
MySQL Question

Calculating MySQL and PHP date difference in days

I am trying to calculate a date difference in days using MySQL and PHP date.

My code

$ArrivalDate = $variants_data['ArrivalDate'];
$daydiff=floor((abs(strtotime(date("d/m/Y")) - strtotime($ArrivalDate))/(60*60*24)));


Output

<td>'.$daydiff.'</td>


Results
I get 93 days instead of 26 days (got 26 days using this calculator http://easycalculation.com/date-day/number-of-days.php)

ArrivalDate value = 2013-05-03 from MySQL table and it changes due to transport delays, etc.

How can I achieve this in PHP?

Answer Source

try this

$daydiff=floor((abs(strtotime(date("Y-m-d")) - strtotime($ArrivalDate))/(60*60*24)));

just change your current date function format so it will give your correct answer means 26 days.