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
 Conversion char to datetime

Author  Topic 

parrao19
Starting Member

1 Post

Posted - 2007-02-06 : 04:58:17
Hi all,

I need to convert a char (a) to datetime in the following query:

select *
from table1
where convert (a, datetime) > '01/31/2007'

this query does not work :(

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-06 : 05:01:35
If you cared enough about your job, you would have read in Books Online.

CONVERT(datatype, value, style)
CAST(value AS datatype)

SELECT * FROM Table1 WHERE CAST(a AS DATETIME) > '20070131'

1) Why are you storing dates as varchar's?
2) What are you really trying to accomplish?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -