I want to display data between the said date range but it is showing the conversion error. What could be he problem?
SELECT * FROM orders WHERE o_date BETWEEN '28-04-2020' and '04-05-2020'
Advertisement
Answer
Try using the standard form for dates:
WHERE o_date BETWEEN '2020-04-28' and '2020-05-04'
Actually, the above uses ISO standard formats for dates, which almost always (but not always depending on internationalization settings) work in SQL Server. You can also drop the hyphens for 100% compliance:
WHERE o_date BETWEEN '20200428' and '20200504'
I would also advise you to use >=
and <
— because such logic works for both dates and date/times:
WHERE o_date >= '20200428' and o_date < '20200505'