Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Elapsed time to seconds

I need to compare elapsed time. Was thinking bellow would do it until I had a elapsed time of more than 25 hours, then it reverts to a negative integer.

Is there a better approach for elapsed time for the likes of 135:00:00?

strtotime('24:59:59') - strtotime('TODAY') = 89999
strtotime('25:00:00') - strtotime('TODAY') = -1659481200

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since you have your time like that you cant use strtotime since it needs a valid timestamp, another approach would be this:

<?php

$time = "24:59:59";
$pieces = explode(":", $time);

$seconds = 0;
$seconds += $pieces[0] * 3600;
$seconds += $pieces[1] * 60;
$seconds += $pieces[2];

echo $seconds;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading