-5

Hello everyone I want to pick the current date of the system by using:

Select GETDATE()

It will give you the result

04/17/2013 06:37:35

But I just want 04/17/2013. Because I don't need the time.

Can anyone please help. Thanks in advance.

user2289490
  • 697
  • 2
  • 7
  • 8

3 Answers3

6

You can convert it to a DATE

SELECT CONVERT(DATE, GETDATE())

Or convert it to a VARCHAR

SELECT CONVERT(CHAR(10), GETDATE(), 101)

The 101 is the format you've requested

msmucker0527
  • 5,164
  • 2
  • 22
  • 36
  • 3
    WHy `VARCHAR(15)` and not `CHAR(10)`? The output will only ever be 10 characters exactly, so there's no need to specify more than that, and there's no reason to make it varying length. – Aaron Bertrand Apr 17 '13 at 13:22
  • Thanks a lot, it actually what I want. – user2289490 Apr 17 '13 at 13:23
  • 1
    @AaronBertrand lazy coding, didn't want to count! I updated it to CHAR(10). I used to use VARCHAR without specifying a length until I read your blog about what can go wrong with that – msmucker0527 Apr 17 '13 at 13:27
2

Use this:

SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY]

For more types of date please visit here.

Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82
1

Something along the lines of:

select convert(varchar(12), GetDate(), 1)

The convert functions third parameter provides a number of different format options for date format.

Guy Hollington
  • 566
  • 5
  • 4