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

3 comments:

  1. thanks for coorect dta related with dates

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

    ReplyDelete