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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 date/time difference between two fields in hours -

Author  Topic 

chamilton
Starting Member

2 Posts

Posted - 2012-02-22 : 09:19:35
I have rows with the following columns
DateAdmitted
TimeAdmitted
DateReleased
TimeReleased
All are DateTime fields (we use sql 2000, 2005, and 2008R2)
Released fields can be null
I need to cull out all rows where the difference between the combo of DateAdmitted, TimeAdmitted and the combo of DateReleased, TimeReleased is less than 4 hours. I have tried the DATEDIFF function using hh but it appears to round the hours so 3 hours and 55 minutes is returning 4

After I posted this, I was reviewing other date differences and found that if I changed my DateDiff to us minutes, I can check for less that 240 and my statement will work.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-22 : 09:34:42
You can use datediff with second instead of hours and then devide it by 3600.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

chamilton
Starting Member

2 Posts

Posted - 2012-02-22 : 09:46:34
Thank you very much - this is working fine!
Go to Top of Page
   

- Advertisement -