View Full Version : Count Up Script?

10-21-2005, 02:27 PM
How do you count up the number of safe working hours a number of employees has worked safely, without getting injured?

For example,

There are 10 employees working on site. There has not been an injury since Mar 3, 1999.

I want to take the number of hours these 10 employees worked safely, without getting injured and make it into something like a hit counter.

I was wondering if I could modify the count up script to do it. Instead of counting up days i would count up hours times the number of employees.

10-21-2005, 03:45 PM
Could you be more specific. What do you need to do?

Philip M
10-21-2005, 03:46 PM
Do please read the posting guidelines. Your query is far too vague. In a day? a week? a year? How is "safely" measured or recorded? Or do you mean the hours worked since he last had an accident? Or what?

And please avoid the expression "Thank you in advance". As a newcomer you should not take other people's interest in your problem and their assistance for granted. The time to offer thanks is after - not before.

Philip M
10-21-2005, 06:26 PM
What you want to achieve is perfectly feasible, but your specification is still too vague.

Are there always 10 (no more, no fewer) employees?
Do they always work 5/6/7 days a week? (how many days?)
Do they always work 7/8/9/10 hours each day? (how many hours?)

I envisage that you want a textbox saying something like
"150654 hours worked since the last accident".

I suppose that if another accident happens you go back to zero!

10-21-2005, 08:14 PM
35 employees.

Lets assume 2080 hrs./yr = 40hrs per week X 52 weeks

This probably will not remain constant, but I can change it manually in the future.

you are correct.

I want a text box that says 9999999 Exposure Hours worked Safely since 2/14/2000.

When someone gets hurt I would reset it to zero.

10-22-2005, 01:17 AM
How do you count up the number of safe working hours a number of employees has worked safely, without getting injured?

Well, I wouldn't suggest leaning back too far in your chair. An ergonomically correct keyboard might also help. If you have any sharp objects on or near you computer, you might want to place them elsewhere. :p ;)

Seriously though, this seems something that could be better, and more accuratley tracked using a server side language. That way you could log the actual working hours by documenting it in a database. Otherwise if \ when you change the number of hours in the javascript solution, it would skew results that had been accumulated under the old formula.


Philip M
10-22-2005, 12:34 PM
I agree with basscyst - you really need a server side language to do this properly, although I take it that the value to be shown is "propaganda" and does not need to be very accurate.

The difficulty with using javascript is that the total hours worked does not go up steadily - only during working hours but not in the middle of the night, or at weekends. Also, what if some employees are sick, or absent, on a certain day? In other words, anything that simply adds 35 hours each hour, or 35 X 8 hours each day, to some starting value is not very useful or reliable. It would be far better if the number was read from an accurate database.

Philip M
10-22-2005, 01:49 PM
The following will give a value which is reasonably accurate (assuming 35 men, 8 hours a day, 5 days a week - but no holidays or absentees). You can if you wish apply a factor to allow for these. In the short term the calculation *5/7 to give hours per week will cause a small inaccuracy (as it does not cover fractions of a week).

<BODY onload="daysNoAccident()">

var date1 = "Feb 14, 2000"
var mons = new Array("Jan", "Feb", "March", "April", "May", "June", "July", "August", "Sept", "Oct", "Nov", "Dec")
var now = new Date();
var mm = now.getMonth();
mm = mons[mm];
var dd = now.getDate();
var yy = now.getYear();
var date2 = mm + " " + dd +", "+ yy;

function daysNoAccident() {
date1 = date1.toString();
date2 = date2.toString();
date1 = Date.parse(date1);
date2 = Date.parse(date2);
date1 /= 1000; date1 /= 60; // minutes
date2 /= 1000; date2 /= 60;
var result = Math.abs(date1 - date2);
result = result/60; // = hours
result = result * 8/24; //hours worked per day
result = result * 5/7; // working days in week
result = result * 35 // number of employees
result = parseInt(result);
document.write ("You have worked " + result + " hours since 14th February 2000 without an accident");

10-22-2005, 02:02 PM

calculates time difference between 2 dates/times

the result is in something like:
52 weeks, 1 days, 0 hours, 0 minutes, and 21 seconds

based on your description:
t1 = lastAccident
t2 = now
var tSH = 0;
tSH += weeks * noEmp * 40; //40 hours per empoyee per week

// 40 hours per week out of 24*7 people lose at work
tmpHours = (24 * days + hours);
tmpHours *= 40/(24*7) * noEmp;

tSH += tmpHours;

10-24-2005, 09:28 PM
Philip M,
Where in the script can I change the text properties?
I got a brain block.
The script works! Thank you.