In the previous, you are using Product.uploadedOn - which I suppose to be DateTime? Have you checked if all of them have the correct date format?
What helps is reproducing with a small example. If you can’t reproduce with a controlled scenario, it might mean you have a messy dataset. Or a bad query.