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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Difference between two times

Author  Topic 

archana23
Yak Posting Veteran

89 Posts

Posted - 2013-06-14 : 11:56:16
Hi,

I need to find the difference between Entertime and LeavingTime minutes.

I have data like this

EnterTime LeavingTime
1500 17:33
2139 21:45


Two 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;
Go to Top of Page

archana23
Yak Posting Veteran

89 Posts

Posted - 2013-06-14 : 13:28:19
Thank you.

Archana
Go to Top of Page
   

- Advertisement -