title: How to Calculate Working Hours including Minutes?
body: <p>I have a query that fetches employee's name, date, working hours, wage and calculate salary based on working hours * wage.</p>
  
  <p>The minutes in working hours that is being calculated are discarded. I only get the value in full hour. Snapshot example:</p>
  
  <p>My main concern is on workingHours and wageAmount</p>
  
  <p><img src="https://i.stack.imgur.com/jTlkQ.jpg" alt="alt text">        </p>
  
  <p>workingHours is displayed as 5. Here is the time sheet snapshot:</p>
  
  <p><img src="https://i.stack.imgur.com/Ul7Bc.jpg" alt="alt text"></p>
  
  <p>As you see shift starts at 10:30 AM and ends at 4:00 PM (excluding lunch time), so the actual total hours is 4 and a half not 5.</p>
  
  <p>Here is the query snippet that calculates the hours:</p>
  
  <pre><code>   DATEDIFF(HOUR, shiftStart.timeEntered, shiftEnd.timeEntered) - DATEDIFF(HOUR, lunchStart.timeEntered, lunchEnd.timeEntered) AS workingHours, 
  </code></pre>
  
  <p><strong><em>MY QUESTION IS:</em></strong></p>
  
  <p><strong>1. How can i calculate working hours accurately with minutes included (discard seconds)?</strong></p>
  
  <p>Since i will be counting the minutes, i will have to calculate the wage per minute so i will have to put the following code that calculates wage per minute:</p>
  
  <pre><code>              ROUND((((DATEDIFF(HOUR, shiftStart.timeEntered, shiftEnd.timeEntered) - DATEDIFF(HOUR, lunchStart.timeEntered, lunchEnd.timeEntered)) * 60) * (cast(((w.wageAmount/60)-((w.wageAmount/60)%.001)) as decimal (18,3)))), 0) AS "SalaryPerMin",
  </code></pre>