Mudassir Hasan
Mudassir Hasan

Reputation: 28771

SQL Server getdate() format

How to get format like 19 Dec 2012 from getdate() function in tsql

select convert(varchar(11),getdate(),?)

Upvotes: 1

Views: 2742

Answers (3)

kevchadders
kevchadders

Reputation: 8335

 -- Can use if SQL 2008 and above (precision to nanoseconds)
 SELECT CONVERT(VARCHAR(12), SYSDATETIME(), 106)

 -- otherwise (precision to miliseconds)
 SELECT CONVERT(VARCHAR(12), GETDATE(), 106)

Upvotes: 1

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239824

Cast and Convert lists the available formats:

106     dd mon yy

looks about right.

I'd generally avoid doing any formatting on the database. Keep dates as dates as long as possible - only convert at the last moment in displaying it to the user (similarly, for any input, prefer to convert it from string into its proper data type as early as possible)

Upvotes: 1

Fred
Fred

Reputation: 5808

select convert(varchar(11),getdate(),106)

Upvotes: 1

Related Questions