Time Duration Calculation

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Time Duration Calculation

Post by ronwill » 2016-08-14 22:01

Hi,

Probably an easy solution to this but beyond me, have enjoyed trying various solutions without success but really need to sort it out now LOL.

I want to add in my Table hooks folder something to calculate the difference between a start and end time:

I've done this, works fine for a larger end date but for example, returns a negative number if start = 22:00:00 and end is 08:00:00

function RotaInput_before_update(&$data, $memberInfo, &$args){

$data['HoursTot'] = $data['EndTime'] - $data['StartTime'];

return TRUE;

Can someone please put up the way to calculate a 'positive time difference between any 2 times (note the time differences will never exceed a 24 hour period... we might do long shift hours but not quite that long!)

Cheers, Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course


User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: Time Duration Calculation

Post by ronwill » 2016-08-15 17:48

Hi,

Thanks for the response, I've looked at the same site link earlier. My problem is I've never done programming before (I might be a pro in excel but never used php etc. before). No matter how many attempts I've made I never get a result (most attempts leave me with a blank page). I'm willing to look for solutions and not looking just for someone else to solve a problem for me except when I really get stuck! I'm stuck now so would appreciate it if someone could just paste the code I need, in the way it should be written so I can copy it and try to understand it. All part of my learning curve!

Cheers, Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: Time Duration Calculation

Post by ronwill » 2016-08-16 02:01

Hi,

If anyone else having same problem, in showing a calculated date field on a time sheet (24hr format) I've solved it in this way (might not be the best but it works!):

My Fields: [StartTime] [EndTime] - both time fields
Hidden Field [Tot1] [Tot2] - decimal field
Result Field Visible: [HoursTot] - decimal field

In my hooks folder:
function RotaInput_before_update(&$data, $memberInfo, &$args){

$data['Tot1'] = strtotime($data['EndTime']) - strtotime($data['StartTime']);
$data['Tot2'] = strtotime($data['StartTime']) - strtotime($data['EndTime']);

$t = date("H/i/s");

if ($data['Tot1'] < 0) {
$data['HoursTot'] = 24 - $data['Tot2']/3600;
} else {
$data['HoursTot'] = $data['Tot1']/3600;
}
return TRUE;
}
Attachments
Cap2.PNG
Cap2.PNG (5.06 KiB) Viewed 6471 times
Cap1.PNG
Cap1.PNG (7.8 KiB) Viewed 6471 times
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Time Duration Calculation

Post by grimblefritz » 2016-08-16 16:49

Ron,

See: http://grimblefritz.com/timediff/

Date and Time fields are of type Date and Time, respectively.

Elapsed field is Decimal 10,2

I used date+time fields. You might choose not to, but I prefer that have hard data rather than assumptions (such as same day, or no more than one trans-midnight event, etc.)

With a little jquery, it's possible to have the elapsed time update as the date/time fields change, but as-is it updates on save. I think that's adequate, but just want to point out that making it real time is possible.

All the source needed is available from the home page. You will, of course, have to massage the field and table names to suit your application. (You should be able to eliminate your Tot1 & Tot2 fields.)

Have fun!

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: Time Duration Calculation

Post by ronwill » 2016-08-16 17:10

Am certainly having fun, well some days are .... won't go there LOL.

Thanks for your Brill example, help, guidance - first class & really appreciated.

I'll give it a go,

Cheers, Ron
P.S. sorry for double post above got a server error/busy message so clicked again & ended up sending 2x - can Admin: pls delete duplicate thks
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

ikatikah
Posts: 6
Joined: 2017-02-02 04:05

Re: Time Duration Calculation

Post by ikatikah » 2017-03-30 01:29

Can you share with me how do you get the time to immediately show the current time?
I can't seem to get the timepicker to show the current time, it will show 1.00 am regardless of what I do.

Thanks in advance.

Post Reply