Monthly Archives: October 2013

date difference or count day or month or year between two dates in php

If you have a get a date difference between two dates like 2 days left or 1 month left count from current date to start date than it code is useful for you..

<?php

$date2 = date(“d-m-Y H:i:s”,strtotime($row[‘end_date_time’]));
// where $row[‘end_date_time’] is your start data
$date1 = date(“d-m-Y H:i:s”,strtotime(date(‘Y-m-d H:i:s’)));

$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));
$hours   =
floor(($diff – $years * 365*60*60*24 – $months*30*60*60*24 –
$days*60*60*24)/ (60*60));
$minuts  = floor(($diff – $years *
365*60*60*24 – $months*30*60*60*24 – $days*60*60*24 – $hours*60*60)/
60);  $seconds = floor(($diff – $years * 365*60*60*24 –
$months*30*60*60*24 – $days*60*60*24 – $hours*60*60 – $minuts*60));

printf(“%d years, %d months, %d days, %d hours, %d minuts\n, %d
seconds\n”, $years, $months, $days, $hours, $minuts, $seconds);

?>

Advertisements