Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in SQL by (20.3k points)

SELECT GETDATE()

Returns: 

2008-09-22 15:24:13.790

I want that date part without the time part: 

2008-09-22 00:00:00.000

How can I get that?

1 Answer

+2 votes
by (40.7k points)
edited by

For SQL Server 2008 and higher versions, you can CONVERT to date:

SELECT CONVERT (date, getdate())

Are you interested in learning SQL from scratch! Have a look at this interesting video on SQL provided by Intellipaat:

For older versions, you can use the following:

 

SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, @your_date))

For Example

SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

Output:

2019-06-22 00:00:00.000

Pros:

  •       varchar<->datetime conversions are not required.
  •       No need to use locale as well.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...