How to calculate working hours, including minutes?

I have a request that allows me to get the name of the employee, date, working hours, wages and calculate wages depending on working hours * wages.

Hours worked are discarded. I get only the cost for a full hour. Example shot:

My main concern is about working hours and salary.

alt text

workingHours is displayed as 5. Here is a snapshot of the time:

alt text

As you can see, the shift starts at 10:30 and ends at 4:00 pm (excluding lunch time), so the actual total hours are 4 and a half, not 5.

Here is a snippet of the query that calculates the clock:

   DATEDIFF(HOUR, shiftStart.timeEntered, shiftEnd.timeEntered) - DATEDIFF(HOUR, lunchStart.timeEntered, lunchEnd.timeEntered) AS workingHours, 

MY QUESTION:

1. How can I accurately calculate the hours of work with the minutes included (cancel seconds)?

, , , :

              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",
+3
3

DATEDIFF(minute, shiftStart.timeEntered, shiftEnd.timeEntered) * 1.0 / 60 , .

+3

-. , sp.

+1

This will return hours and minutes: CAST (DATEDIFF (MINUTE, StartTime, EndTime) AS DECIMAL) / 60

0
source

Source: https://habr.com/ru/post/1768728/


All Articles