Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert DateTime to VARCHAR() without dashes and colons

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?

like image 714
user2984031 Avatar asked Dec 09 '22 04:12

user2984031


1 Answers

In SQL Server 2012 or later you can use the Format() function to get this result:

Select Format(YourColumn, N'yyyyMMddHHmmss')
like image 123
Siyual Avatar answered Dec 31 '22 20:12

Siyual