Wednesday, 11 September 2013

Convert string formatted as yyyymmddhhnn to datetime

Convert string formatted as yyyymmddhhnn to datetime

I have a table in an SQL Server database with a date field in it,
presented as varchar in yyyymmddhhnn format (where nn is minutes). For
example, 200012011200 would be 01 Dec 2000 12:00. I need to convert this
to a datetime value, but none of the convert codes seems to cover it. It's
closest to ISO format yyyymmdd but that doesn't include the time part, so
calling convert(datetime, MyDateField, 112) fails.
The time part is important, so I can't just strip it off. How can I
convert this to datetime?

No comments:

Post a Comment