How Can I Reliably Convert YYYYMMDDhhmmss To A Date/time?
I have a data source where the dates come back like this: 20150614140520-0500 How can I display this better? It doesn't actually have to be converted technically, this is just for
Solution 1:
You have to take the first 14 characters, from the example above:
print convert(datetime,stuff(stuff(stuff(LEFT('20150614140520-0500',14) , 9, 0, ' '), 12, 0, ':'), 15, 0, ':'))
Solution 2:
Please try this:
convert(datetime,stuff(stuff(stuff(datevalue, 9, 0, ' '), 12, 0, ':'), 15, 0, ':')) ConvertedDate
As suggested by Dinesh Kumar Rajendran in his blog: https://rdineshkumar.wordpress.com/tag/how-to-convert-yyyymmddhhmmss-to-datetimedatetime-in-sql-server/
Post a Comment for "How Can I Reliably Convert YYYYMMDDhhmmss To A Date/time?"