question

rk_tech avatar image
rk_tech asked

Calculate Time difference

,I want to calculate Total times from two different times for payroll hours purpose. Table has Time data type. or should I use datetime. Any suggestion to use better way.
time
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Cyborg avatar image
Cyborg answered
I prefer to use DateTime, as its easy to calculate the difference when your shifts cover cross dates like night shift. use datediff(hh, StartDateTime, EndDateTime) for the difference.
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sp_lock avatar image sp_lock commented ·
Have you tried playing with the cast/convert function for when you have done your DATEDIFF?
1 Like 1 ·
sp_lock avatar image sp_lock commented ·
Which example have you tried? Look at the link below and the link to cast/convert http://msdn.microsoft.com/en-gb/library/ms189794.aspx
1 Like 1 ·
rk_tech avatar image rk_tech commented ·
Thank you for quick reply, based on your answer I got the hh part but how about MM, and I assumed I have to add AM PM into date and how to use Military time? Result should calculate in MM:SS.
0 Likes 0 ·
rk_tech avatar image rk_tech commented ·
I tried but I am not getting the result, I am new to T-SQL, can give me an example. Thanks
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.