[Solved] I have a query with a between clause that is return wrong days [closed]


Let’s break this down:

WHERE convert(varchar(10),F_Presence.ts, 120) 
  between '2022-03-01' and '2022-03-02'
  1. Converting the column to a string means you will never, ever, ever be able to take advantage of an index on that column, whether it exists yet or not.
  2. Using BETWEEN is horrible for date ranges for multiple reasons.
  3. Using a format like YYYY-MM-DD is unsafe, because it can be misinterpreted as YYYY-DD-MM in a lot of cases.

All these and more at Dating Responsibly.

Here is how the query should work:

WHERE F_Presence.ts >= '20220301'
  AND F_Presence.ts <  '20220303'

2

solved I have a query with a between clause that is return wrong days [closed]