Question : Converting nvarchar to datetime in mssql?

Using MSSQL 2005.
I have a table that has 2 col. the person who set it up decided to store dates in "nvarchar" field and now i need to start comparing dates which is becoming hard, so i want to convert the nvarchar to datatime in mssql, when i try that, it gives me a warning data will be lost. ! any idea how i can do this? here is some sample data in those columns

November 18, 2009
2008-04-24 15:22:47
24/11/2009 2:31:06 PM
2009-02-13 09:36:00

Answer : Converting nvarchar to datetime in mssql?

the safest dateformat is yyyyMMdd, also make sure that you put them inside quotes

SELECT *
FROM MyTable
WHERE ( (MyDate Like '??/??/%'  and  CONVERT(datetime,MyDate,103) >= '20071111'  ) OR
       CAST(MyDate as datetime ) > =  '20091111'  )

Random Solutions  
 
programming4us programming4us