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

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

archana23
Yak Posting Veteran

74 Posts

Posted - 06/14/2013 :  11:56:16  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3333 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:
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

74 Posts

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

Archana
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000