[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.8

Time Calculations  for a Timesheet

Asked by SEUPB in JavaScript

Tags: javascript, time, calculations, timesheets

Hi Guys,

At the moment I am trying to convert a paper based timesheet into a web based solution. I have managed to code out the layout and feel of the timesheet & managed to grab some solutions from already answered qns in Experts Exchange. I've tried to modify some of the coding to make it suit my needs but I haven't had much luck. Basically I have several problems, which are..

1. I need to calculate the total hours worked between 2 times a start time and finish time, which I have got working but I can't get the format of totalHr1 to be 00:00 so if hours worked is 10hrs it should be 10:00.

2. Once I get the total hours worked calculated I need to make a further calculation to subtract break times from total hours which I have got working but sometimes the time format isn't correct ie when I enter 1hr for breaks and it gives 9::0 because of the convert format function. The format should be 00:00 aswell.

3. This problem is to do with flexi times, standard hours for mon - thurs is 7.25mins. I need to subtract the hrWorked by Standard and obtain the extra time worked or how much time wasn't work.

Below is the current coding for my timesheet....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Flexible Working Hours Timesheet</title>
<link href="/flexiTimesheet.css" rel="stylesheet" type="text/css" />

<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>

<script type="text/javascript"><!--converts a number into time format-->
    function sayampm(t) {
      if (t>= "0000"&& t<= "1159"); else
      if (t>= "1200"&& t<= "2359");
    }
    function checkEntry(e) {
      var text= e.value;
      if (text.length== 2) text= "00:"+ text; else
      if (text.length== 3) {
        if (text.substr(0, 1)== ":") text= "00"+ text; else
        text= "0"+ text.substr(0, 1)+ ":"+ text.substr(1, 2);
      } else
      if (text.length== 4) {
        if (text.substr(1, 1)== ":") text= "0"+ text; else
        text= text.substr(0, 2)+ ":"+ text.substr(2, 2);
      } else if (text.length> 0) {
        text= text.replace(/:/, "");
        text= text.substr(text.length- 4, 2)+ ":"+ text.substr(text.length- 2, 2);
      }
      e.value= text;

      if (text!= "") {
        var timetext= text.substr(0, 2)+ text.substr(3, 2);
        if (timetext>= "0000"&& timetext<= "2359"&& !isNaN(timetext)) sayampm(timetext); else {
          alert('Please Enter a Valid Format in HH:MM');
          e.value= "00:00";
        }
      }
    }
      
       function calculate(){
               var start = document.getElementById("startTime1").value.split(':');
               var end = document.getElementById("finishTime1").value.split(':');
               var total = document.getElementById("totalHr1");

               var shour = parseInt(start[0].substring(0,1)== '0'? start[0].substring(1):start[0]);
               var smin = parseInt(start[1]);
               var ehour = parseInt(end[0].substring(0,1)== '0'? end[0].substring(1):end[0]);
               var emin = parseInt(end[1]);
               
               if (shour>ehour)
                    alert("error");
               else if (shour == ehour)
                    total.value = "00:"+(emin-smin);
               else{
                    if (emin>=smin)
                         total.value=(ehour-shour)+":"+(emin-smin);
                    else
                         total.value=(ehour-shour-1)+":"+(60-smin+emin);
               }
          }
</script>

<script language="javascript">
function calculateWorked(){
               var total = document.getElementById("totalHr1").value.split(':');
               var breaks = document.getElementById("lunch1").value.split(':');
               var worked = document.getElementById("hrWorked1");

               var shour = parseInt(total[0].substring(0,1)== '0'? total[0].substring(1):total[0]);
               var smin = parseInt(total[1]);
               var ehour = parseInt(breaks[0].substring(0,1)== '0'? breaks[0].substring(1):breaks[0]);
               var emin = parseInt(breaks[1]);
               
               if (shour == ehour)
                    worked.value = "00:"+(smin-emin);
               else{
                    if (smin>=emin)
                         worked.value=(shour-ehour)+":"+(smin-emin);
                    else
                         worked.value=(shour-ehour-1)+":"+(60-emin+smin);
               }
          }
</script>

<script language="javascript">
function cumulative(){
               var worked = document.getElementById("hrWorked1").value.split(':');
               var standard = document.getElementById("standard1").value.split(':');
               var credit = document.getElementById("credit1");

               var shour = parseInt(worked[0].substring(0,1)== '0'? worked[0].substring(1):worked[0]);
               var smin = parseInt(worked[1]);
               var ehour = parseInt(standard[0].substring(0,1)== '0'? standard[0].substring(1):standard[0]);
               var emin = parseInt(standard[1]);
               
               if (shour == ehour)
                    credit.value = "00:"+(smin-emin);
               else{
                    if (smin>=emin)
                         credit.value=(shour-ehour)+":"+(smin-emin);
                    else
                         credit.value=(ehour-shour-1)+":"+(60-emin+smin);
               }
          }
</script>
</head>

<body>
      <div class="containerAll">
            <div class="contentMain">
                  <div class="container">
                        <form action="" method="POST" name="flexi" id="flexi">
                        <table bgcolor="#efefef" width="100%" border="1" bordercolor="#cccccc" cellpadding="2" cellspacing="3">
                              <tr>
                                      <td>Name :<input class="textfield" type="text" id="empname" name="empname" value=""/></td>
                                    <td>Job Title :<input class="textfield" type="text" id="jobTitle" name="jobTitle" value=""/></td>
                                    <td>Location :<input class="textfield" type="text" id="location" name="location" value=""/></td>
                                    <td>Period Commencing :<input class="textfield" type="text" id="period" name="period" value=""/></td>
                              </tr>
                        </table>
                        
                        <blockquote></blockquote>
                        
                        <table bgcolor="#efefef" width="100%" border="1" bordercolor="#cccccc" cellpadding="2" cellspacing="3">
                              <tr>
                                      <td>Flex Bands :</td>
                                    <td>08:00am - 10:00am</td>
                                    <td>12:00pm - 2:00pm</td>
                                    <td>4:00pm - 6:00pm</td>
                                    <td>Core Time :</td>
                                    <td>10:00am - 12:00pm</td>
                                    <td>2:00 - 6.00pm</td>
                              </tr>
                        </table>
                        
                        <blockquote></blockquote>
                        
                        <table bgcolor="#efefef" width="100%" border="1" bordercolor="#cccccc" cellpadding="2" cellspacing="3">
                              <tr>
                                    <td></td>
                                      <td>Date :</td>
                                    <td>Day :</td>
                                    <td>Start Time :</td>
                                    <td>Finish Time :</td>
                                    <td>Total Hours for Day :</td>
                                    <td>Lunch Break :<br />| Minimum 30mins |</td>
                                    <td>Hours Worked :</td>
                                    <td>Standard Hours :</td>
                                    <td>Cumulative :<br />| Credit B/F |</td>
                                    <td>Cumulative :<br />| Debit B/F |</td>
                              </tr>
                              
                              <tr>
                                    <td align="center">wk:1</td>
                              </tr>
                              
                              <tr>
                                    <td align="center"><a href="javascript:NewCal('txtDate1','ddmmyyyy')"><img src="cal.gif" width="20" height="20" border="0" alt="Select From Date"></a></td>
                                      <td><input name="txtDate1" type="text" id="txtDate1" value="" size="8" /></td>
                                    <td>Mon</td>
                                    <td><input name="startTime1"  type="text" id="startTime1" value="" size="8" onBlur="checkEntry(this);"/></td>
                                    <td><input name="finishTime1" type="text" id="finishTime1" value="" size="8" onBlur="checkEntry(this),calculate();"/></td>
                                    <td><input name="totalHr1" type="text" id="totalHr1" value="" size="8"/></td>
                                    <td><input name="lunch1" type="text" id="lunch1" value="" size="8" onBlur="checkEntry(this),calculateWorked();"/></td>
                                    <td><input name="hrWorked1" type="text" id="hrWorked1" value="" size="8" onBlur="cumulative(),checkEntry(this);"/></td>
                                    <td><input name="standard1" type="text" id="standard1" value="07:25" size="8" readonly=""/></td>
                                    <td><input name="credit1" type="text" id="credit1" value="" size="8" /></td>
                                    <td><input name="debit1" type="text" id="debit2" value="" size="8" /></td>
                              </tr>
                                                                               </table>
</div></div></div>

P.S is it possible to get the current functions to work with all the fields? Instead of having to code extra functions for each field? For example my time sheet contains 4 weeks so I have labelled the fields as mon1,mon2,mon3 etc etc.

Many Thanks for any help given.
 
Related Solutions
 
Loading Advertisement...
 
[+][-]11/09/07 08:43 AM, ID: 20250822Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/07 09:11 AM, ID: 20251055Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/07 09:18 AM, ID: 20251116Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/07 01:25 PM, ID: 20253231Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 02:41 AM, ID: 20263158Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 02:49 AM, ID: 20263185Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 03:59 AM, ID: 20263374Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 04:02 AM, ID: 20263385Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 04:18 AM, ID: 20263427Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 04:20 AM, ID: 20263430Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 04:40 AM, ID: 20263496Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 05:04 AM, ID: 20263591Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 05:10 AM, ID: 20263614Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 05:32 AM, ID: 20263743Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 05:56 AM, ID: 20263898Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 06:36 AM, ID: 20264164Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 06:47 AM, ID: 20264248Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 07:43 AM, ID: 20264727Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 07:48 AM, ID: 20264772Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 07:59 AM, ID: 20264860Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 08:07 AM, ID: 20264920Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 08:08 AM, ID: 20264930Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 08:18 AM, ID: 20265034Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 08:34 AM, ID: 20265169Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 08:36 AM, ID: 20265186Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 09:02 AM, ID: 20265392Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 09:03 AM, ID: 20265408Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 09:18 AM, ID: 20265532Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 09:41 AM, ID: 20265709Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 09:53 AM, ID: 20265792Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/07 10:09 AM, ID: 20265892Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/07 10:25 AM, ID: 20266009Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/13/07 02:02 AM, ID: 20270480Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/13/07 02:32 AM, ID: 20270586Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/13/07 02:54 AM, ID: 20270652Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/13/07 04:06 AM, ID: 20270865Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/13/07 04:14 AM, ID: 20270896Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/13/07 04:16 AM, ID: 20270907Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: JavaScript
Tags: javascript, time, calculations, timesheets
Sign Up Now!
Solution Provided By: HonorGod
Participating Experts: 2
Solution Grade: A
 
[+][-]11/13/07 04:34 AM, ID: 20270977Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_2_20070628