View Full Version : Adding Days, Hours, and Minutes
WebPlaya
08-03-2004, 06:36 PM
Hello all, does any one know if there is a calculator out there that would be used to add hours? i.e. 8 hours would be one working business day. so
0 Day 4 Hr 30 Min
+ 0 Day 3 Hr 00 Min
+ 0 Day 0 Hr 30 Min
------------------------
1 Day 0 Hr 00 Min (which is 8 Hours).
I have run reports every day and there are just too many numbers so I thought that if there is a calculator online of if someone has it and wouldn't mind sharing it, I would really appreciate it.
I tried looking in Java Script section but could not figure out where to begin.
Thank you for any help.
MattJakel
08-03-2004, 07:50 PM
I went ahead and wrote a script that will do it.
<html>
<head>
<title>
Day/Hour/Min Calc
</title>
</head>
<body style="font-family:arial;">
<h3>JavaScript Day/Hour/Minute Calculator</h3>
<script type="text/javascript">
function recalc() {
form = document.forms.calc
var totalMin = parseInt(form.min1.value) + parseInt(form.min2.value)
var totalHour = parseInt(form.hour1.value) + parseInt(form.hour2.value)
var totalDay = parseInt(form.day1.value) + parseInt(form.day2.value)
var minOver = Math.floor(totalMin/60)
totalMin -= minOver * 60
totalHour += minOver
var hourOver = Math.floor(totalHour/8)
totalHour -= hourOver * 8
totalDay += hourOver
form.day3.value = totalDay
form.hour3.value = totalHour
form.min3.value = totalMin
}
</script>
<form name="calc">
Days: <input type="text" name="day1" size="3"> Hours: <input type type="text" name="hour1" size="3"> Minutes: <input type="text" name="min1" size="3"><br>
+ Days: <input type="text" name="day2" size="3"> Hours: <input type type="text" name="hour2" size="3"> Minutes: <input type="text" name="min2" size="3"><br>
= Days: <input type="text" name="day3" size="3"> Hours: <input type type="text" name="hour3" size="3"> Minutes: <input type="text" name="min3" size="3"><br>
<input type="button" onclick="recalc()" value="Recalculate">
</form>
</body>
</html>
Hope this helps!
Matt
WebPlaya
08-03-2004, 08:44 PM
Hey Matt, thanks a lot for the reply. I really appreciate it.
I think I m missing something somewhere. I used that form and nothing is happening.
I tried with Excel file, I formatted the fields as HH:MM and then SUM of those fields and then devide the SUM by 8 (since I want the days to be 8 Hours long) and it's giving me the right answer.
But once again, if it's web based then it's much easier to use.
I am wondering if there is a way to add unlimited number of hours. I mean if I could add
4:30 + 5:27 + 3:20 + 0:17 and on and on and on..... and then hit calculate and it would give me the answer...
I feel really dumb right now but hopefully someone will help me.. :)
Thanks again.
MattJakel
08-03-2004, 09:22 PM
Hmm... I tested it in Firefox but not IE... I don't feel like booting Windows so I'm not going to test it in IE. I just realized that I accidently left out the </head> closing tag... add that before body and see if it helps. About allowing for multiple times, you could have a text box with times seperated by spaces and use JavaScript's indexOf and substring to break the string up into the minutes and hours to add, or (and I think this way would be easier) have a text input at the top that asks how many times to add and when you input a number and submit it, have JavaScript write to the innerHTML of a div.
If you want me to, I can code this for you too.
Matt
WebPlaya
08-03-2004, 10:11 PM
If you can do it, I will really appreciate it. However, I do not want you to go out of your way. :)
I thank you so much in advanced, regardless what you decide to do. Any help is much appreciated.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.