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?
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
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