Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert datetime value to yyyymmddhhmmss in SQL server?

How to convert datetime value to yyyymmddhhmmss?

for example From 2014-04-17 13:55:12

To 20140417135512

like image 895
vignesh Avatar asked Apr 17 '14 13:04

vignesh


People also ask

How do you convert date format from Yyyymmdd to yyyy-mm-dd in SQL?

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].


2 Answers

Since SQL Server Version 2012 you can use:

SELECT format(getdate(),'yyyyMMddHHmmssffff') 
like image 125
JPT Avatar answered Sep 30 '22 09:09

JPT


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 
like image 23
jpw Avatar answered Sep 30 '22 07:09

jpw