For those of you who may be interested, this would perform better if you change VARCHAR to CHAR.See this post (stackoverflow.com/questions/59667/…) for more details.

DECLARE @now datetime SET @now = GETDATE() select convert(nvarchar(MAX), @now, 0) as output, 0 as style union select convert(nvarchar(MAX), @now, 1), 1 union select convert(nvarchar(MAX), @now, 2), 2 union select convert(nvarchar(MAX), @now, 3), 3 union select convert(nvarchar(MAX), @now, 4), 4 union select convert(nvarchar(MAX), @now, 5), 5 union select convert(nvarchar(MAX), @now, 6), 6 union select convert(nvarchar(MAX), @now, 7), 7 union select convert(nvarchar(MAX), @now, 8), 8 union select convert(nvarchar(MAX), @now, 9), 9 union select convert(nvarchar(MAX), @now, 10), 10 union select convert(nvarchar(MAX), @now, 11), 11 union select convert(nvarchar(MAX), @now, 12), 12 union select convert(nvarchar(MAX), @now, 13), 13 union select convert(nvarchar(MAX), @now, 14), 14 --15 to 19 not valid union select convert(nvarchar(MAX), @now, 20), 20 union select convert(nvarchar(MAX), @now, 21), 21 union select convert(nvarchar(MAX), @now, 22), 22 union select convert(nvarchar(MAX), @now, 23), 23 union select convert(nvarchar(MAX), @now, 24), 24 union select convert(nvarchar(MAX), @now, 25), 25 --26 not valid union select convert(nvarchar(MAX), @now, 100), 100 union select convert(nvarchar(MAX), @now, 101), 101 union select convert(nvarchar(MAX), @now, 102), 102 union select convert(nvarchar(MAX), @now, 103), 103 union select convert(nvarchar(MAX), @now, 104), 104 union select convert(nvarchar(MAX), @now, 105), 105 union select convert(nvarchar(MAX), @now, 106), 106 union select convert(nvarchar(MAX), @now, 107), 107 union select convert(nvarchar(MAX), @now, 108), 108 union select convert(nvarchar(MAX), @now, 109), 109 union select convert(nvarchar(MAX), @now, 110), 110 union select convert(nvarchar(MAX), @now, 111), 111 union select convert(nvarchar(MAX), @now, 112), 112 union select convert(nvarchar(MAX), @now, 113), 113 union select convert(nvarchar(MAX), @now, 114), 114 union select convert(nvarchar(MAX), @now, 120), 120 union select convert(nvarchar(MAX), @now, 121), 121 --122 to 125 not valid union select convert(nvarchar(MAX), @now, 126), 126 union select convert(nvarchar(MAX), @now, 127), 127 --128, 129 not valid union select convert(nvarchar(MAX), @now, 130), 130 union select convert(nvarchar(MAX), @now, 131), 131 --132 not valid order BY style output style Apr 28 2014 AM 0 04/28/14 1 2 28/04/14 3 4 28-04-14 5 28 Apr 14 6 Apr 28, 14 7 8 Apr 28 2014 :580AM 9 04-28-14 10 14/04/28 11 140428 12 :580 13 :580 14 2014-04-28 20 2014-04-28 .580 21 04/28/14 AM 22 2014-04-28 23 24 2014-04-28 .580 25 Apr 28 2014 AM 100 04/28/2014 101 20 102 28/04/2014 103 104 105 106 Apr 28, 2014 107 108 Apr 28 2014 :580AM 109 110 2014/04/0428 112 :580 113 :5-04-28 120 2014-04-28 .5-04-28T.5-04-28T.580 127 28 جمادى الثانية 1435 :580AM 130 28/06/1435 :580AM 131 SQL Server 2012 has a new function , FORMAT: you can use custom date time format strings: pages imply it is also available on SQL2008R2, but I don't have one handy to test if that's the case.

Example usage (Australian datetime): While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.

Link-only answers can become invalid if the linked page changes.

- From Review DECLARE @DAY INT DECLARE @MONTH INT DECLARE @YEAR INT DECLARE @DATE DATETIME @DATE = GETDATE() SELECT @DAY = DATEPART(DAY,@DATE) SELECT @MONTH = DATEPART(MONTH,@DATE) SELECT @YEAR = DATEPART(YEAR,@DATE) While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.

Please take time and use the contact form to recommend improvements you would like to see and help us build a “community for the community”.

Please feel free to support us by donating or liking our page from the social network bar in the top right hand corner.All proceeds will go back into improving/advertising the site to make a better experience for you.However, I would caution against using this in a database query or concatenated into a SQL statement.Databases require a specific formatting string to be used.You are better off zeroing out the time part and using the Date Time as a SQL parameter if that is what you are trying to accomplish.At No Strings we don’t follow the usual dating portal restrictions and the site is 100% free and will always be.