1

How can I display only date while using getdate() function?

When I am using

select getdate() as Today's Date

It is giving me:

2016-05-18 08:32:07.100

But I only need:

 2016-05-18

How to get this?

Felix Pamittan
  • 31,544
  • 7
  • 41
  • 67
Red Devil
  • 2,343
  • 2
  • 21
  • 41

2 Answers2

5

Use convert. The first argument truncates the length, and the last specifies the format you want the date in:

SELECT Convert(varchar(10), getdate(), 103) as [Today's Date]
John Bingham
  • 1,996
  • 1
  • 12
  • 15
1

If you are using SQL Server 2012+, you may also want to look at FORMAT - which in my opinion is a bit nicer to read/use.

Example: SELECT FORMAT(GETDATE(), 'dd/MM/yyyy')

See this msdn link for more info

Abbath
  • 582
  • 2
  • 7