finding the difference between two date time fileds in php

by guruprasad 2014-07-23 10:17:33

To find exact differences between two date time fileds using php in year , day and minute wise:
   
$date1 = strtotime("2014-07-23 09:59:03");
$date2 = strtotime("2014-07-23 10:02:23");

$diffTime = $date2 - $date1;

$year = ($diffTime/(60*60*24*365));
$day = ($diffTime/(60*60*24))%365;
$hour = ($diffTime/(60*60))%24;
$min = ($diffTime/60)%60;

echo $year." Year(s) ".$day." Day(s) ".$hour." Hour(s) ".$min." min(s);


Output:
0 Year(s) 0 Day(s) 0 Hour(s) 3 min(s).
				
638
like
0
dislike
0
mail
flag

You must LOGIN to add comments