Fix exception on sorting by date