How to convert YYYYMMDDHHMMSS to Datetime in Microsoft Sql Server

24-12-2014
To convert yyyymmddhhmmss string format to datetime in Microsoft Sql Server, you can use below sql script:

update PageContent
set NewDatetimeColumn = convert(datetime, stuff(stuff(stuff(OldDateAsStringColumn, 9, 0, ' '), 12, 0, ':'), 15, 0, ':'))

NewDatetimeColumn column is defined in the PageContent table and will be used to store OldDateAsStringColumn's string value after conversion operation.

After run this script, for example, 20090513024903 string value will be 2009-05-13 02:49:03.000

© 2019 All rights reserved. Codesenior.COM