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.
geetha velusamyPosted Nov 3, 2021, 1:02 PM
Amit GuptaPosted Dec 16, 2020, 5:47 AM
Riddhi ValechaPosted Dec 16, 2020, 4:04 AM
But, here - 15:00:00 is 3pm for the same day.
In my case, Atul have worked from 4.35pm to 11pm - means he has completed his shift, and worked extra till 3am next day.
select convert(time, CONVERT(varchar(15),CAST('03:00' AS TIME),100) - CONVERT(varchar(15),CAST('23:00' AS TIME),100))
In this query, I am getting AM and PM Correctly, i.e. - CONVERT(varchar(15),CAST('03:00' AS TIME),100) - this is 3AM.select datediff(hour , CONVERT(varchar(15),CAST('23:00' AS TIME),100), dateadd(dd,1,CONVERT(varchar(15),CAST('03:00' AS TIME),100)) )
But, this query is applicable only for AM time, how do I do it for all the timestamps?Sachin SinghPosted Dec 16, 2020, 1:45 AM
Riddhi ValechaPosted Dec 16, 2020, 12:14 AM
Here, Shift Timing for employee Atul is - 4.35PM to 11.00PM.
In 24-hour format, it is 4.35 to 23.
Sachin SinghPosted Dec 16, 2020, 12:09 AM
Riddhi ValechaPosted Dec 15, 2020, 11:39 PM
Hello sir,
I need to get the hours in sql query...
Sachin SinghPosted Dec 15, 2020, 9:06 PM