Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Difference between two times
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

89 Posts

Posted - 06/14/2013 :  11:56:16  Show Profile  Reply with Quote

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.


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 06/14/2013 :  12:16:49  Show Profile  Reply with Quote
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:
		CAST(STUFF(RIGHT('0'+EnterTime,4),3,0,':') AS DATETIME),
		CAST(LeavingTime AS DATETIME))
Go to Top of Page

Yak Posting Veteran

89 Posts

Posted - 06/14/2013 :  13:28:19  Show Profile  Reply with Quote
Thank you.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000