SQLTeam.com | Weblogs | Forums

How to find a record between two dates

Hi,
I want to get data from date 17/05/2019 to date 18/05/2019
I have used following way but it not work properly Please Help

1)SELECT convert(nvarchar(255),InsertedOn,103),* FROM InWardMaster WHERE InsertedOn >= '17/05/2019' AND InsertedOn <= '18/05/2019'
It gives data only on date 17/05/2019 not 18/05/2019

2)SELECT convert(nvarchar(255),InsertedOn,103),* FROM InWardMaster WHERE (convert(nvarchar(255),InsertedOn,103)between convert(nvarchar(255),'17/05/2019',103) and convert(nvarchar(255),'18/05/2019',103))

It gives data only on date 17 &18 but all months like january, Feb, etc.

3)SELECT InsertedOn,* FROM InWardMaster WHERE (convert(nvarchar(255),InsertedOn,103)>='17/05/2019' and convert(nvarchar(255),InsertedOn,103)<='18/05/2019')
It gives data only on date 17 &18 but all months like january, Feb, etc.

The field InsertedOn is probably a datetime field so this:

would get rows from the 17th no matter the time, but on the 18th only if time is 00:00:00.

You could change it to:
SELECT convert(nvarchar(255),InsertedOn,103),* FROM InWardMaster WHERE InsertedOn >= '17/05/2019' AND InsertedOn < '19/05/2019'

1 Like

Thanks,
Its Working for me, Thanks for Quick Response.