I want to figure out the difference in time by seconds. I keep getting 0 as a results and wants to know if someone could assist me. The times will be pulled from a database.
Here is an example of what I want to be able to do.
$TimeStart = "04:30:45 am";
$TimeEnd = "04:31:46 am";
$Difference = $TimeEnd - $TimeStart . "seconds";
I know this is not a very illustrated example and I know it is probably not that simple.
Here is the code that is currently on my site now:
$TimeStart = strtotime($VisitsRow['TimeStart']);
$TimeEnd = strtotime($VisitsRow['TimeEnd']);
$TimeDifference = ($TimeEnd - $TimeStart);
if ($VisitsRow['TimeEnd'] == "") {
$Timeto = "Incomplete";
} else {
if ($TimeDifference <= 60) {
$Timeto = "< a minute";
} else if ($TimeDifference <= 0) {
$Timeto = "< a second";
} else {
$Timeto = round($TimeDifference, 2)." seconds";
}
if ($TimeDifference >= 60) {
$MinutesDiff = $TimeDifference / 60;
$Timeto = round($MinutesDiff, 2)." minutes";
}
}
I have simply tried the example of what I want above and am getting a negative number. This is why I am needing assistance.
Thank you everyone for helping me solve this. My problem was that it was gathering the times in 24 hr format and not the standard. Once I solved this everything works perfectly.