Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005 Date Formatting [DD-Mon-YY hh:mm:ss]

I have datetimes stored in a table in SQL Server 2005 in the format of:

 2012-04-16 00:00:00.000

I need to get date in the format of 16-Apr-2012 00:00:00 in my query result.

What is the best method of doing this?

like image 283
amarcy Avatar asked Oct 15 '25 04:10

amarcy


1 Answers

Select Convert(VarChar(20),[SomeDate],113)

113, is 24h format and includes millisecond, the varchar(20) chops them off.

For further reference one of my favourite MSDN pages T-SQL Convert DateTime To String

like image 89
Tony Hopkinson Avatar answered Oct 17 '25 22:10

Tony Hopkinson