Page 1 of 1

Calculating time difference

Posted: 2014-06-08 22:01
by johnboy
Hi,

New to AppGini and PHP I need to calculate the total time for an event.

I have a start time (time field) and completion time (time field).

In the before update hook I have the following formula:

$data['TotalTime'] = $data['CompletionTime'] - $data['StartTime'];

This always gives the result -12:00:20A.

Guidance appreciated.

John

Re: Calculating time difference

Posted: 2014-06-15 17:05
by a.gneady
Try:

Code: Select all

$diff_seconds = strtotime($data['CompletionTime']) - strtotime($data['StartTime']);
$data['TotalTime'] = gmdate("H:i:s", $diff_seconds);
This should work assuming both times (start and completion) are in the same day.

Re: Calculating time difference

Posted: 2014-07-10 07:50
by dallo
thanks for the code a.gneady.

very much appreciated.

Re: Calculating time difference

Posted: 2014-07-10 10:22
by a.gneady
dallo wrote:very much appreciated.
You're always welcome :D