Calculating time difference

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
johnboy
Posts: 3
Joined: 2014-06-07 06:31

Calculating time difference

Post by johnboy » 2014-06-08 22:01

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

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Calculating time difference

Post by a.gneady » 2014-06-15 17:05

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.
:idea: AppGini plugins to add more power to your apps:

dallo
Posts: 8
Joined: 2014-05-19 14:43

Re: Calculating time difference

Post by dallo » 2014-07-10 07:50

thanks for the code a.gneady.

very much appreciated.

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: Calculating time difference

Post by a.gneady » 2014-07-10 10:22

dallo wrote:very much appreciated.
You're always welcome :D
:idea: AppGini plugins to add more power to your apps:

Post Reply