Tuesday, October 19, 2010

Converting datetimes to just the date (and to pretty text) in SQLServer

From http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype

DATEADD(dd, 0, DATEDIFF(dd, 0, [Datetime])) AS TheDate,

Also, this helps for text formatting

CONVERT(nvarchar, TheDate, NNN)
101 - 10/19/2010
102 - 2010.10.19
103 - 19/10/2010
104 - 19.10.2010
105 - 19-10-2010
106 - 19 Oct 2010
107 - Oct 19, 2010
108 - 00:00:00
109 - Oct 19 2010 12:00:00:000AM
110 - 10-19-2010
111 - 2010/10/19
112 - 20101019
113 - 19 Oct 2010 00:00:00:000

No comments:

Post a Comment