How do I check if a given datetime object is “between” two datetimes?

前端 未结 4 1937
耶瑟儿~
耶瑟儿~ 2021-02-14 12:05
my_event = Event.objects.get(id=4)
current_time = datetime.datetime.now()

How do I do check if my current time is between them?

my_eve         


        
4条回答
  •  庸人自扰
    2021-02-14 12:34

    Your answer is the way to go as long as start_time and end_time don't have an associated tzinfo class. You can't directly compare a naive datetime with a timezoned-datetime.

提交回复
热议问题