How to convert datetime
value to yyyymmddhhmmss
?
for example From 2014-04-17 13:55:12
To 20140417135512
Convert Char 'yyyymmdd' back to Date data types in SQL Server. Now, convert the Character format 'yyyymmdd' to a Date and DateTime data type using CAST and CONVERT. --A. Cast and Convert datatype DATE: SELECT [CharDate], CAST([CharDate] AS DATE) as 'Date-CAST', CONVERT(DATE,[CharDate]) as 'Date-CONVERT' FROM [dbo].
Since SQL Server Version 2012 you can use:
SELECT format(getdate(),'yyyyMMddHHmmssffff')
This seems to work:
declare @d datetime set @d = '2014-04-17 13:55:12' select replace(convert(varchar(8), @d, 112)+convert(varchar(8), @d, 114), ':','')
Result:
20140417135512
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With