Can't compare naive and aware datetime.now() <= challenge.datetime_end

后端 未结 9 1267
离开以前
离开以前 2020-12-02 07:58

I am trying to compare the current date and time with dates and times specified in models using comparison operators:

if challenge.datetime_start <= datet         


        
9条回答
  •  自闭症患者
    2020-12-02 08:39

    Just:

    dt = datetimeObject.strftime(format) # format = your datetime format ex) '%Y %d %m'
    dt = datetime.datetime.strptime(dt,format)
    

    So do this:

    start_time = challenge.datetime_start.strftime('%Y %d %m %H %M %S')
    start_time = datetime.datetime.strptime(start_time,'%Y %d %m %H %M %S')
    
    end_time = challenge.datetime_end.strftime('%Y %d %m %H %M %S')
    end_time = datetime.datetime.strptime(end_time,'%Y %d %m %H %M %S')
    

    and then use start_time and end_time

提交回复
热议问题