Riddhi Valecha

Riddhi Valecha

  • 425
  • 3.2k
  • 397.1k

SQL Server - Time Difference in 24-Hour Format

Dec 15 2020 11:51 AM

Hello TEam,

I am again stuck up with SQL Query. 

I have the following data -
EMPCODE PUNCHDATE PUNCHTIME INOUT NAME
187729 02-01-2020 23:31:40 O Atul
187729 03-01-2020 15:31:40 O Atul
187729 04-01-2020 03:48:40 O Atul
187729 06-01-2020 05:31:48 O Atul
187729 07-01-2020 14:46:39 O Atul
187729 08-01-2020 15:32:34 O Atul
187729 09-01-2020 14:47:55 O Atul
187729 10-01-2020 15:31:23 O Atul
187729 11-01-2020 18:36:33 O Atul
187729 13-01-2020 15:33:36 O Atul
 
Here, the employee "Atul" has shift from 04:35PM to 11:00PM. 
 
Now, here I need the total number of hours extra that "Atul" has worked - i.e. after 11.00PM, i.e. here where punchtime is "23:31".
 
How do I calculate the difference between "23:00" and "23:31".
 
For Punchtime  "15:33:36", it is - 11PM to 3PM ->4hrs. This is not coming from Datediff function.
 
Please guide. 

Answers (8)