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
 How to find the difference between 2 times in SQL

Author  Topic 

brentos2004
Starting Member

4 Posts

Posted - 2007-04-10 : 12:08:33
Hi,

I am trying to find the difference between two times (timeIN, timeOut)and then populate a new field called "duration of stay" with the difference.

The two times are in a table called attendance and the new duration of stay field is to be populated in a table called factAttend2

Is there an easy way to do this?

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-10 : 12:11:50
Difference in what terms? hour, minutes, seconds, ms?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-10 : 12:12:42
Check out the DateDiff function in books on line (documentation).


************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-10 : 12:16:55
And here is an article of what pitfalls to look out for when using DATEDIFF
http://www.sqlteam.com/item.asp?ItemID=26922


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

brentos2004
Starting Member

4 Posts

Posted - 2007-04-10 : 12:17:47
The timeIN and timeOut fields are in the following format

01/01/2002 08:02:00

so what I want it to do is disregard the date part and just use the two times to find the difference. In some cases this is hours and some it is just minutes so it would probably be better if it could be done in minutes.

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-10 : 13:35:50
You have gotten 2 answers and 1 follow-up question to your original problem.
What is bothering you?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -