Page 1 of 1
Calc number of hours between to times
Posted: Fri Aug 21, 2020 10:29 am
by trevorm
Hello
I have form on my site which is a time sheet for staff to enter hours worked. Please can anyone help me with the Expression to obtain the number of hours between two times.
i.e.
The number of hours between times added in two fields
"time_in" to "time_out" equals "total_hours"
Thank you.
Re: Calc number of hours between to times
Posted: Fri Aug 21, 2020 11:33 am
by Pablo
In expressions, you can you can use any valid JavaScript.
https://stackoverflow.com/questions/776 ... javascript
Re: Calc number of hours between to times
Posted: Fri Aug 21, 2020 12:29 pm
by trevorm
Thank you for your reply. The answer you have provided is complicated and deals with dates - I am only concerned with hours and minutes difference between to times on the same day.
I would appreciate it if you could give me a simple answer to my question - I am a neanderthal not a programmer.
Thanks in anticipation
Re: Calc number of hours between to times
Posted: Fri Aug 21, 2020 12:42 pm
by Pablo
Unfortunately, there is no easier way. This will require JavaScript functions.
'Expressions' are basically just standard JavaScript options. The software provides standard options for the most common situations.
But for advanced functionality you will need to write a script, because there is no way to implement an UI option for every possible combination anyone can think of.
Re: Calc number of hours between to times
Posted: Fri Aug 21, 2020 12:51 pm
by trevorm
Thanks anyway - guess I'll have to find someone else who can assist.
Re: Calc number of hours between to times
Posted: Fri Aug 21, 2020 12:55 pm
by lummis
Re: Calc number of hours between to times
Posted: Fri Aug 21, 2020 5:36 pm
by WWBman
If you still require help then using some suggestions from lummis's link I've created a test project that may help.
http://www.mediafire.com/file/exzvm2n67 ... d.wbs/file
The form's first 2 editboxes are setup as 'time' format which may or may not be as you want.
Re: Calc number of hours between to times
Posted: Sat Aug 22, 2020 11:21 am
by WWBman
FWIW:
I found a few bugs in the sample code which hopefully I've corrected.
The updated project has the same link:
http://www.mediafire.com/file/exzvm2n67 ... d.wbs/file
Re: Calc number of hours between to times
Posted: Sat Aug 22, 2020 12:59 pm
by trevorm
Thank you very much for your help, it is much appreciated. I have not had a chance to review your file just yet but will do so on my return home shortly.
Thanks again.
Re: Calc number of hours between to times
Posted: Sun Aug 23, 2020 12:54 pm
by trevorm
Thank you WWBman, this exactly what i required. As Pablo commented, it is more complicated than Initially imagined.
To clarify - to adapt your project to suit my page where I have start and finish times for each day of the week, I assume I would need seven separate scripts. That being the case, would I be right to use the "ONCHANGE" event in each of the time-in (start_time) fields for each day to trigger an Action (your script, suitably modified for each day) to calculate each of my daily totals with the relevant Target set as the appropriate daily Total Hours field for each day.
However, thinking about this - as I have seven such cases on the page for Monday to Sunday, would it be feasible or even possible to have seven separate html boxes with a specific script for each day or should I have one script somehow to include 7 unique sub-routines, one for each day? Not sure how this all works.
Re: Calc number of hours between to times
Posted: Sun Aug 23, 2020 1:47 pm
by WWBman
Hi trevorm,
If you want something like the example below then it would probably take me a long time to code and fully test.
Have you looked at any timesheet tools from the web? There are quite a few if you google it.
E.g.
https://www.actitime.com/software-colle ... timesheet/
I think for the long run and for future possible changes it would be preferable to use one of those.

Re: Calc number of hours between to times
Posted: Sun Aug 23, 2020 2:03 pm
by BaconFries
Carrying on from WWBman suggestion here is a nice "pen" in jQuery it displays start / finish and a breaktime with the total at end of working week.
https://codepen.io/jclarkedb/pen/vrWxVm
https://www.jqueryscript.net/time-clock ... -Grid.html
Re: Calc number of hours between to times
Posted: Mon Aug 24, 2020 10:34 am
by trevorm
Thank you both very much for your assistance - at least now have something to steer me.