Mlungisi Mlungisi - 5 months ago 49
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)));



I get 93 days instead of 26 days (got 26 days using this calculator

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download