December 5, 2024
sql-database

SQL BETWEEN operator for datetime

This article describes about the SQL between operator, how to use SQL between operator in date time operation?

sql

Create a Temp table. For the sql query is

Create Table #Temp (Id varchar(2), Name varchar(15), Dob datetime);

 
Then insert some data into the table.
insert into #Temp values(‘1’, ‘Komal’, ‘1984-10-27 02:10:00’);
insert into #Temp values(‘2’, ‘Ajay’, ‘1985-04-19 12:10:25’);
insert into #Temp values(‘3’, ‘santosh’, ‘1986-11-16 23:46:34’);

If we run the query then we will find

1 Komal 1984-10-27 02:10:00.000
2 Ajay 1985-04-19 12:10:25.000

Create Table #Temp (Id varchar(2), Name varchar(15), Dob datetime);

insert into #Temp values(‘1’, ‘Komal’, ‘1984-10-27 02:10:00’);
insert into #Temp values(‘2’, ‘Ajay’, ‘1985-04-19 12:10:25’);
insert into #Temp values(‘3’, ‘santosh’, ‘1986-11-16 23:46:34’);

Select * From #Temp
Where Dob BETWEEN ‘1984-01-01 00:00:00’ And ‘1986-1-1 00:00:00’;

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

One thought on “SQL BETWEEN operator for datetime

Leave a Reply

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