Convert char(24) to datetime
Posted on 2014-04-10
I am trying to convert a char(24) field to datetime but it does not work, please help?
A sample data would be:
SELECT top 1 convert(datetime, '2014-03-05 17:03:18.518') from CounterData
and obviously it works. However, when I replace the date and time data with the field name which has the data type of char(24), it fails:
select top 1 convert(datetime, CounterDateTime) from CounterData
(The above query also should return '2014-03-05 17:03:18.518')
The error message is:
Conversion failed when converting date and/or time from character string.
How can I make this work easily without managing the data char by char? By the way, I am using MS SQL 2008.
Thank you in advance