Skip to content
Advertisement

How to query on DATE on DATETIME Column in SQL Server?

Here is my table having column(completed_on) with datetime field. However I need to filter results based on date only.

SELECT * FROM myTable
WHERE completed_on 
-- Pass Date Range in condition

enter image description here

Advertisement

Answer

Please tyr this

SELECT * FROM myTable
WHERE completed_on BETWEEN 'date1' and 'Date2'
-- Pass Date Range in condition

Another option is-

SELECT * FROM myTable
WHERE completed_on >= '20190701' --Sample start Date 
and completed_on < '20190722' 
-- This will make sure dates will be inclued less then 
-- the given date. You have to pass this with 
-- understanding what you want. If you want 
-- date 7 to be included, please set the end date to 8 
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement