Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I need to find the difference between Entertime and LeavingTime minutes.I have data like thisEnterTime LeavingTime 1500 17:332139 21:45Two time formats are different so How can i calculate the difference between those 2 times?Thank you.Archana
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2013-06-14 : 12:16:49
If you store the data using correct data types, this type of problem can be avoided. So consider doing that if at all possible. If that is not an option, calculate it like this:
SELECT DATEDIFF( mi, CAST(STUFF(RIGHT('0'+EnterTime,4),3,0,':') AS DATETIME), CAST(LeavingTime AS DATETIME))FROM YourTable;