resolved date selection issues in aggregate function