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
 Subtracting DATETIME columns

Author  Topic 

x0200196
Starting Member

2 Posts

Posted - 2009-06-05 : 14:38:26
Hello. I'm new to these forums and I wasn't sure where I should post this.

Basically I need to pull a report that shows all agent phone calls that are 10 seconds or less. Unfortunately, our tables only have CallStartDt and CallEndDt. So I need to subtract column CallStartDt from CallEndDt so I can see the calls that are 10 seconds or less. I tried SELECT *,callenddt-callstartdt AS difference FROM ACDCallDetail but it gave me the error "Invalid operator for datatype op: SUBTRACT type: DATETIME."

So.. can anyone help me out? If there is an even simpler way then that would be great.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-05 : 14:42:38
You can use datediff.
Sample:
declare @ddd datetime
set @ddd=dateadd(second,-50,getdate())

select DATEDIFF(second,@ddd,getdate())



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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-07 : 03:18:35
quote:
Originally posted by x0200196

Hello. I'm new to these forums and I wasn't sure where I should post this.

Basically I need to pull a report that shows all agent phone calls that are 10 seconds or less. Unfortunately, our tables only have CallStartDt and CallEndDt. So I need to subtract column CallStartDt from CallEndDt so I can see the calls that are 10 seconds or less. I tried SELECT *,callenddt-callstartdt AS difference FROM ACDCallDetail but it gave me the error "Invalid operator for datatype op: SUBTRACT type: DATETIME."

So.. can anyone help me out? If there is an even simpler way then that would be great.


Are CallEndDt and v datetime fields? if yes you can use the below

WHERE CallEndDt <=DATEADD(ss,10,CallStartDt)
Go to Top of Page

x0200196
Starting Member

2 Posts

Posted - 2009-06-08 : 12:33:16
quote:
Originally posted by visakh16

quote:
Originally posted by x0200196

Hello. I'm new to these forums and I wasn't sure where I should post this.

Basically I need to pull a report that shows all agent phone calls that are 10 seconds or less. Unfortunately, our tables only have CallStartDt and CallEndDt. So I need to subtract column CallStartDt from CallEndDt so I can see the calls that are 10 seconds or less. I tried SELECT *,callenddt-callstartdt AS difference FROM ACDCallDetail but it gave me the error "Invalid operator for datatype op: SUBTRACT type: DATETIME."

So.. can anyone help me out? If there is an even simpler way then that would be great.


Are CallEndDt and v datetime fields? if yes you can use the below

WHERE CallEndDt <=DATEADD(ss,10,CallStartDt)



Thank you so much. It worked!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-09 : 12:05:51
welcome
Go to Top of Page
   

- Advertisement -