SQL Server Admin
T-SQL Articles

December 17, 2007

Return date without time using Sql 2005




By default, you get both the date and time value whenever you retrieve a datetime value from the database. So something like :

SELECT GETDATE()

returns 2007-12-17 21:17:33.933

Let us quickly see how to return only the date portion in different formats

YYYY-MM-DD
SELECT CONVERT(VARCHAR(10), GETDATE(), 120)

returns 2007-12-17

MM-DD-YYYY
SELECT CONVERT(VARCHAR(10), GETDATE(), 110)

returns 12-17-2007


DD-MM-YYYY
SELECT CONVERT(VARCHAR(10), GETDATE(), 105)

returns 17-12-2007


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

4 Responses to "Return date without time using Sql 2005"
  1. DC said...
    February 13, 2008 8:50 PM

    thanks for coorect dta related with dates

  2. try said...
    December 11, 2008 11:46 AM

    great information

  3. Anonymous said...
    May 1, 2009 6:27 AM

    Thanks!

  4. Anonymous said...
    December 13, 2011 8:47 PM

    Super work, can you also specify how to put "/" in place of "-"

 

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