You could avoid calling `past_n_date.date()` inside the loop by saving it to a variable.