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
 convert varchar into smalldatetime

Author  Topic 

kneel
Starting Member

36 Posts

Posted - 2008-11-04 : 09:42:00
Hello AlL,


How can I convert varchar into small datetime ? my query is like
SELECT * FROM TABLE WHERE DATETIME = CONVERT(SMALLDATETIME,'21/10/2008 15:10:10')

it gives me error as
Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.


Does anyone know how can I write this query ?
Thanks in advance

--kneel

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-04 : 09:50:27

SELECT * FROM TABLE WHERE DATETIME = CONVERT(SMALLDATETIME,'20081021 15:10:10')

Madhivanan

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

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-11-04 : 10:18:08
SET DATEFORMAT DMY

or 11/10/2008 will return Nov 10 instead of October 11, which looks like why your query produced and out-of-range error

Jim
Go to Top of Page
   

- Advertisement -