Reputation: 97
I have a column which has data as such: 2014-08-15 15:11:00
I want to run a select on this column and end up with this: 20140815151100
Basically YYYYMMDDhhmmss
.
I tried to do a CAST()
and CONVERT()
to VARCHAR()
and then remove the dashes & colons but when I do that, I end up with this: Aug 15 2014 3:11PM
And that's not what I want. Can someone give me a hand?
Upvotes: 5
Views: 22594
Reputation: 16917
In SQL Server 2012
or later you can use the Format()
function to get this result:
Select Format(YourColumn, N'yyyyMMddHHmmss')
Upvotes: 18