It's not entirely clear from your question, but you appear to be storing your dates as strings. That is the fundamental cause of your problem: you're comparing strings, not dates, and the strings aren't even in a "sortable" format (
yyyy-MM-dd
).
For example, with a string comparison, a value starting with
"2/"
is greater than a value starting with
"11/"
, because
"2"
is greater than
"1"
.
And with the dates in
d/M/Y
order,
"23/01/2001"
is going to be "between" the values
"22/04/2018"
and
"24/04/2021"
.
You need to change your column type to use a proper date type. For example, in SQL Server, use
date
. You will avoid problems like this, and reduce the amount of storage required by your table at the same time.
As a quick-and-dirty workaround, you could try converting the columns in your query. But the performance will not be great!
WHERE Convert(date, cdDatePoliceRequestFIRNo, 3) BETWEEN '20180422' and '20210423'
NB: For date literals, always use the unambiguous format
yyyyMMdd
, with no separators.