fixing the query for the last time, Properly count day boundaries