I always forget how to do this so I figured I would create a post on it. A lot of times when querying a database with a date i will get the long date like so:

2011-05-12 00:00:00

Simple way to solve this, especially if you’re sending this to someone as a report is to use convert like so:

CONVERT(VarChar, GetDate(), 101)

Of course you can replace “GetDate()” with a value from your database like:

CONVERT(VarChar, dbo.[mytable].[my-datebase-date], 101)

Here’s some information on the command including changing the dates into other formats
http://msdn.microsoft.com/en-us/library/ms187928.aspx

Hope this helps someone.

Advertisements