php - Date and time difference display 30min as 5 -
i have tried compare 2 dates , time using php code
<?php $a = "2013-01-10 10:30:00"; $b = "2013-01-10 12:00:00"; echo str_replace('-','',(strtotime($a) - strtotime($b))/(60*60)); ?>
code working fine display 30 min 5 not able checks db values idea fix 1
strtotime()
alone can calculate difference. there no need use str_replace()
. try -
echo (strtotime($b) - strtotime($a))/60;
will return difference in minutes
ie. 90
. if want 1.30
have basic calculations. -
$mins = (strtotime($b) - strtotime($a))/60; if ($mins > 60) { echo ((int)($mins/60)).'.'.($mins%60); } else { echo $mins; }
Comments
Post a Comment