How to Query Date and Time in MS-SQL

If you want to obtain data from any specific date, just put the date in the format ‘mm/dd/yyyy’. If the column data type is timestamp, you can convert to date data type by using the function CAST()

select * from sales where sold_at = '01/20/2021';

If you want to obtain the sales amount done on each day in a specific period of time, for example between 07:00 am and 08:00 am, you can extract the time from a datetime column by using the CAST() function and then filter in a range of time. Finally you can group by date.

select sold_at, sum(revenue) 
from sales 
where cast (sales_timestamp AS time) between '07:00' AND '08:00'
group by sold_at order by sold_at;