Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i try to compare 2 datetime and get the different in minutes and second and after i refer this topic How to get time difference in minutes in PHP yes that code can show the different but in minute:

$to_time = strtotime("2008-12-13 18:42:00");
$from_time = strtotime("2008-12-13 18:41:58");

echo round(abs($to_time - $from_time) / 60,2). " minute";

so how to show in minute and second from above code? My php version is 5.2.17 .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
556 views
Welcome To Ask or Share your Answers For Others

1 Answer

$minutes = round(abs($to_time - $from_time) / 60,2);
$seconds = abs($to_time - $from_time) % 60;

echo "$minutes minute, $seconds seconds";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...