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)
 I need help converting a data field to datetime

Author  Topic 

binici
Starting Member

5 Posts

Posted - 2007-12-13 : 11:39:07
I have this statement that I need to execute:

DELETE FROM callcenter..tRecipQueue WHERE DATEDIFF(dd, expiration_date, GetDate()) > 368

Of course it doesn't work because expiration_date is a varchar data type, which contains MM/DD/YYYY value. How can I efficiently cast or convert that data, so my sp won't complain about this error?

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.

Thanks!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-13 : 11:44:13
[code]where expiration_date >= dateadd(day, datediff(day, 0, getdate()), -368)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-14 : 03:36:47
1 Always use proper DATETIME datatype to store dates
2 in Tan's query use
where cast(expiration_date as datetime)>= dateadd(day, datediff(day, 0, getdate()), -368)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -