Reputation: 3789
I want to display a date column in a particular format in SQL Server and need some help with that.
Current display 2013-04-04 15:45:38.497
, required display 20130404154538
With the below function
CONVERT(VARCHAR(30),GETDATE(), 112)
I can get 20130404
Similar thing can be achieved in oracle by
TO_CHAR(date_field,'yyyymmddhh24mmss')
Upvotes: 0
Views: 82
Reputation: 3472
If you are using SQL Server 2012 you could use:
SELECT Format(dateField, 'yyyyMMddHHmmss');
Upvotes: 1
Reputation: 263743
how about concatenating the result of 112
and 108
and replacing :
with empty string?
SELECT REPLACE(CONVERT(VARCHAR(30),dateField, 112) +
CONVERT(VARCHAR(30),dateField, 108), ':', '')
FROM TableName
which is the same with
SELECT CONVERT(VARCHAR(30),dateField, 112) +
REPLACE(CONVERT(VARCHAR(30),dateField, 108), ':', '')
FROM TableName
Upvotes: 3