Question: How to compare two dates in a SQL Server database with `between` statement and remove time from it's value? 

This is my code:

```
select 
    sum(TbDeals.dealPrice) as sumofvalues 
from 
    DNN_TbDeals
where 
    Deals.dealStartDate between Convert(Date, Convert(datetime, '2017-07-10 22:21:16.233')) 
                            and Convert(Date, Convert(datetime, '2017-07-10 22:21:16.233'))

```

Answer: 
Assuming `Deals.dealStartDate` is a `DateTime` column, you don't have to convert twice - If you want to do a `between` 2 dates, convert it once with a fixed format, this way you don't have to remove the time string.

Also - in your question, you posted a `between` with the **exact same dates**. This is probably the reason you are getting no results.

Please try the following:

```
select sum(TbDeals.dealPrice) as sumofvalues 
from DNN_TbDeals
where 
    Deals.dealStartDate
    between 
        Convert(datetime, '2016-01-01 22:21:16.233', 101)
    and 
        Convert(datetime, '2017-08-28 22:21:16.233', 101)

```
Hope I understood well your question, to compare two datetimes format where the differences are in the hours, you can do:

```
SELECT DATEDIFF(HOUR,@DATETIME1,@DATETIME2) AS DIFFERENCES

```

To take the hours from a datetime variable you can do:

```
DECLARE @dateTime2 AS DATETIME = '2013-04-04 00:00:00.000'

SELECT CONVERT(DATE,@dateTime2, 101)

```

In you case, if you want to compare two dates and then take the hours your query can be like:

```
DECLARE @dateTime1 AS DATETIME= '2017-07-10 22:21:16.233'
DECLARE @dateTime2 AS DATETIME= '2017-07-10 22:21:16.233'

SELECT
    SUM(TbDeals.dealPrice) ASsumofvalues 
FROM
    DNN_TbDeals
WHERE
    Deals.dealStartDate BETWEEN CONVERT(DATE,@dateTime1,101)
                            AND CONVERT(DATE,@dateTime2,101)

```