Get Difference between two dates
Date2 – dd-mm-yyyy
Break and get the part of the date, month and year and show the difference.
$today = date(“d-m-Y”);
$d1 = substr($d, 0,-8);
$d2 = substr($today, 0,-8);
$m1 = substr($d, 3,-5);
$m2 = substr($today, 3,-5);
$y1 = substr($d, -4);
$y2 = substr($today, -4);
$date1 = “$y1-$m1-$d1”;
$date2 = “$y2-$m2-$d2”;
$diff = abs(strtotime($date2) – strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff – $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff – $years * 365*60*60*24 – $months*30*60*60*24)/ (60*60*24));
And you can show your result anywhere on your web page like –
This will be shown like –
dd days, mm months and yy years lefts.