61

I have a SQL table that has a CreationDate field.

I have getdate() in the computed column specification formula.

I would like to know how to get just the date portion, that is, '2012-08-24' instead of '2012-08-24 10:45:17.740'.

Jon Schneider
  • 23,615
  • 19
  • 137
  • 163
Rui Martins
  • 2,076
  • 7
  • 30
  • 50
  • 1
    If this is SQL Server, which it looks like, you should use the SQL-server tag in addition to your current tags – podiluska Aug 24 '12 at 08:52

5 Answers5

86

If you are using SQL Server 2008 or later

select convert(date, getdate())

Otherwise

select convert(varchar(10), getdate(),120)
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
podiluska
  • 50,144
  • 7
  • 94
  • 100
7

try this:

select convert (date ,getdate())

or

select CAST (getdate() as DATE)

or

select convert(varchar(10), getdate(),121)
Joe G Joseph
  • 22,627
  • 4
  • 51
  • 56
3

Try this:

SELECT CONVERT(date, GETDATE())
András Ottó
  • 7,469
  • 1
  • 28
  • 37
3
SELECT CONVERT(date, GETDATE())
John Woo
  • 249,283
  • 65
  • 481
  • 481
3
SELECT CAST(FLOOR(CAST(GETDATE() AS float)) as datetime)

or

SELECT CONVERT(datetime,FLOOR(CONVERT(float,GETDATE())))