better query date range detection