Queryset of people with a birthday in the next X days

前端 未结 6 1852
春和景丽
春和景丽 2021-01-03 13:29

how do i get queryset of people with a birthday in the next X days? I saw this answer, but it does not suit me, because gets people only with current year of birth.

6条回答
  •  自闭症患者
    2021-01-03 13:56

    If X is a constant that you know:

    import datetime
    future_date = datetime.date.today() + datetime.timedelta(days=X)
    Profile.objects.filter(
        birth_date__month=future_date.month,
        birth_date__day=future_date.day
    )
    

    Something like that.

提交回复
热议问题