SQL Server Admin
T-SQL Articles

October 09, 2010

Display Dates in a Particular Format in SQL Server




Questions of displaying dates in either ‘mm/dd/yy’ format or ‘dd/mm/yyyy’ format and so on have been asked numerous times. A very good link to check out the different Date and Time styles is the CAST and CONVERT functions in BOL

Here’s an example of displaying dates in ‘dd/mm/yyyy’ format

DECLARE @TT TABLE
(
ID int,
DateOfEntry DateTime
)

INSERT INTO @TT
SELECT 1, '08/22/2010' UNION ALL
SELECT 2, '09/01/2010' UNION ALL
SELECT 3, '10/03/2010' UNION ALL
SELECT 4, '10/07/2010'

SELECT ID, CONVERT(VARCHAR(10),DateOfEntry,103) AS 'dd/mm/yyyy'
FROM @TT

OUTPUT

image


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter



 
  Feedback:

comments

1 Response to "Display Dates in a Particular Format in SQL Server"
  1. Joel said...
    October 11, 2010 4:00 PM

    Thanks for the quick recap. It's amazing how often the question about dates comes up - even from experienced DBA's!

 

Copyright © 2009-2011 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions