+2 votes
1 view
in SQL by (22.4k 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.3k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...