Nov 27, 2009 #1 MJV57 Programmer Joined Apr 18, 2009 Messages 87 Location CA Can anyone helpme with converting a varchar(8) column to a datetime value. I try this but it fails: CAST( startdate as datetime )
Can anyone helpme with converting a varchar(8) column to a datetime value. I try this but it fails: CAST( startdate as datetime )
Nov 28, 2009 #2 markros Programmer Joined May 21, 2007 Messages 3,150 Location US Can you show some of your dates first? Upvote 0 Downvote
Nov 30, 2009 Thread starter #3 MJV57 Programmer Joined Apr 18, 2009 Messages 87 Location CA Example dates: 20090905 20091109 Upvote 0 Downvote
Nov 30, 2009 #4 bborissov Programmer Joined May 3, 2005 Messages 5,167 Location BG First you must be sure that ALL records contains values that can be converted to datetime. Code: SELECT * FROM YourTable WHERE ISDATE(YourField) = 0 That will give you all records that can not be converted. So your query should look like this: Code: SELECT CAST(YourField AS datetime) AS DateNameField FROM YourTable WHERE ISDATE(YourField) = 1 Borislav Borissov VFP9 SP2, SQL Server 2000/2005. Upvote 0 Downvote
First you must be sure that ALL records contains values that can be converted to datetime. Code: SELECT * FROM YourTable WHERE ISDATE(YourField) = 0 That will give you all records that can not be converted. So your query should look like this: Code: SELECT CAST(YourField AS datetime) AS DateNameField FROM YourTable WHERE ISDATE(YourField) = 1 Borislav Borissov VFP9 SP2, SQL Server 2000/2005.