Home > Software engineering >  SQL: not showing the same date when given from and to date?
SQL: not showing the same date when given from and to date?

Time:06-20

When trying to get same date in between, it is just throwing an empty table.

CodePudding user response:

Try this one:

select * from tblNames 
where BirthDate >= '2022-06-13 00:00:00' and BirthDate <= '2022-06-13 23:59:59'

OR

select * from tblNames
where BirthDate between '2022-06-13 00:00:00' and '2022-06-13 23:59:59' 

Be careful about Time part in datetime Data Type.

CodePudding user response:

select * from tblNames
where cast(BirthDate as date) between '20220613' and '20220713' 

or

select * from tblNames
where BirthDate >'20220612' and BirthDate<'20220714'
  • Related