Calc number of hours between to times

All WYSIWYG Web Builder support issues that are not covered in the forums below.
Forum rules
IMPORTANT NOTE!!

DO YOU HAVE A QUESTION OR PROBLEM AND WANT QUICK HELP?
THEN PLEASE SHARE A "DEMO" PROJECT.



PLEASE READ THE FORUM RULES BEFORE YOU POST:
http://www.wysiwygwebbuilder.com/forum/viewtopic.php?f=12&t=1901

MUST READ:
http://www.wysiwygwebbuilder.com/getting_started.html
WYSIWYG Web Builder FAQ
Post Reply
trevorm
 
 
Posts: 84
Joined: Sat Mar 14, 2020 3:43 pm

Calc number of hours between to times

Post 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.
User avatar
Pablo
 
Posts: 21708
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Calc number of hours between to times

Post by Pablo »

In expressions, you can you can use any valid JavaScript.
https://stackoverflow.com/questions/776 ... javascript
trevorm
 
 
Posts: 84
Joined: Sat Mar 14, 2020 3:43 pm

Re: Calc number of hours between to times

Post 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
User avatar
Pablo
 
Posts: 21708
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Calc number of hours between to times

Post 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.
trevorm
 
 
Posts: 84
Joined: Sat Mar 14, 2020 3:43 pm

Re: Calc number of hours between to times

Post by trevorm »

Thanks anyway - guess I'll have to find someone else who can assist.
lummis
 
 
Posts: 213
Joined: Sun Apr 24, 2011 9:18 am
Location: UK

Re: Calc number of hours between to times

Post by lummis »

You may find some inspiration here:
https://stackoverflow.com/questions/217 ... ith-jquery
WWBman
 
 
Posts: 917
Joined: Fri Jan 08, 2010 6:10 pm

Re: Calc number of hours between to times

Post 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.
WWBman
 
 
Posts: 917
Joined: Fri Jan 08, 2010 6:10 pm

Re: Calc number of hours between to times

Post 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
trevorm
 
 
Posts: 84
Joined: Sat Mar 14, 2020 3:43 pm

Re: Calc number of hours between to times

Post 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.
trevorm
 
 
Posts: 84
Joined: Sat Mar 14, 2020 3:43 pm

Re: Calc number of hours between to times

Post 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.
WWBman
 
 
Posts: 917
Joined: Fri Jan 08, 2010 6:10 pm

Re: Calc number of hours between to times

Post 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.
Image
User avatar
BaconFries
 
 
Posts: 5364
Joined: Thu Aug 16, 2007 7:32 pm

Re: Calc number of hours between to times

Post 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
trevorm
 
 
Posts: 84
Joined: Sat Mar 14, 2020 3:43 pm

Re: Calc number of hours between to times

Post by trevorm »

Thank you both very much for your assistance - at least now have something to steer me.
Post Reply