Sunday , 25 June 2017
Home » SQL » Filter between dates in sql server

Filter between dates in sql server

Filter between dates in sql server

filter_dataIn every application of yours, you are going to do some kind of filtering. In this article you will learn how to filter your data between dates. The same way can be use to filter any other numbers as well.

I am going to show you how to filter data in 2 ways. The first way is by using sql server built-in command which is ‘between’. The second way is by using our logic and creating our own sql query.

Let me start with the first one. The command for filtering date with between command is the following:


Now this is going to list the data including 1st of January and 31st of January.

The other way of filtering data is the creating query. The query below is going to give you similar results but not the same.


Now as you see in the results there is only 2 records… Why? Let me explain why. In the query we say greater then 1st of January and less then 27th of January. So is 1st grater than 1st? No. That’s why it skips that record. the same thing happens with 27th.

Now If you change the query to the following by just adding  equal sign (=) to both greater and less sign

filtering dates

you will get the same results as you got in the first query where you used ‘between’ command.

Check Also

Stored Procedure vs Functions

Stored Procedure vs Functions In this article I am going to show you the differences …

Leave a Reply

Your email address will not be published. Required fields are marked *