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

前端 未结 4 1931
耶瑟儿~
耶瑟儿~ 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:22

    you can use a simple if comparing three dates, like this

    if date1 < yourdate < date2:
      ...do something...
    else:
      ...do ...
    

提交回复
热议问题