Updated the query for the timespan