SQL Server equivalent of MySQL DATE_FORMAT()
You can try this:
DECLARE @description VARCHAR(1000) = 'test'
DECLARE @INLastUpdated DATETIME = '2012-12-21 14:32:22'
SET @description = @description + ' '
+ LEFT(CONVERT(VARCHAR(8), @INLastUpdated, 8), 5) + ' '
+ CONVERT(VARCHAR(20), @INLastUpdated, 106)
SELECT @description
But be careful as format 106 depends on local language settings. Read more on MSDN
Related videos on Youtube
denimknight
I am currently working as a SQL Server DBA using SQL Server 2008 R2 and 2012. In the past I have worked as a VBA contractor / Access Developer / Finance Analyst / Data Analyst.
Updated on September 15, 2022Comments
-
denimknight over 1 year
Hope we're having a good day and all set for Christmas.
Got a quick question. I'm converting a MySQL function into SQL Server, I've got most of the function converted except for one part which has the following:
@description = CONCAT(@description, date_format(@INLastUpdated, '%H:%i %d %b %Y'))
What I'm trying to do is to basically recreate the date_format function to format the date in the same way specified, but I'm not sure how to do it. from what I've seen in the MySQL documentation the format selected would give hour:minute day / short month name / year.
Anyone got any ideas?
-
Jamiec over 11 yearsHere's an idea: Format dates in the display, not the database!
-