Add option to retrieve min and max datetimes from database