Skip to content
Advertisement

SQL between date range returning a wrong result

I’m writing a SQL query to get rows between a date range format: mm/dd/yyyy

I used the between operator but the result shows out of the range dates

The expected result : dates of year 2020 only

The actual result is:

Advertisement

Answer

I assume that you use SQL Server.
Maybe you think that % is a wildcard char in this condition denoting any char, but this is not the case.
You can use % with the operator LIKE but not with BETWEEN.
Use the function FORMAT():

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement