SQL BETWEEN operator for datetime
This article describes about the SQL between operator, how to use SQL between operator in date time operation?
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’);
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
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’);
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’;
Where Dob BETWEEN ‘1984-01-01 00:00:00’ And ‘1986-1-1 00:00:00’;
No comments