0

i basicly need to get actual time(time1) and see how many hours and minutos to time2. Its a countdown, how many time untill time2.

I have been making this

def schedule_task():
    exp_h = 23 
    exp_m = 5
    now = datetime.datetime.now()

    if len(str(exp_m))==1:
        exp_m=str("0")+str(exp_m)

    date_time_str = str(exp_h)+":"+str(exp_m)+":00"
    exp_now = datetime.datetime.strptime(date_time_str,"%H:%M:%S").time()
    fdate = datetime.datetime.now().strftime("%H:%M:%S")

    locl_h = now.strftime("%H")
    locl_m = now.strftime("%M")

    remain = datetime.datetime.combine(now.today(), fdate.time()) - datetime.datetime.combine(now.today(), exp_now)

    lbl_remaing.config(text="Request will be sent in "+str(remain), bg="darkgrey",fg="blue")

    if locl_h.strip()==exp_h.strip() and locl_m.strip()==exp_m.strip():
        print("run func")
    else:
        lbl_remaing.after(1000, schedule_task)

Having this error

print("----> ",datetime.datetime.combine(now.today(), fdate.time())

  • datetime.datetime.combine(now.today(), exp_now.time())) AttributeError: 'str' object has no attribute 'time'
ralphgz
  • 23
  • 7
  • Does this answer your question? [Calculate Time Difference Between Two Pandas Columns in Hours and Minutes](https://stackoverflow.com/questions/22923775/calculate-time-difference-between-two-pandas-columns-in-hours-and-minutes) – Hamzah Mar 25 '22 at 16:02
  • i really didnt want to use pandas in order not to have another import, already using datetime, would like to stick with it instead of importing another module. but thanks anyway – ralphgz Mar 25 '22 at 16:10

1 Answers1

0

Got it:

start_time = datetime.time(int(exp_h), int(exp_m), 00)
stop_time = datetime.time(int(locl_h), int(locl_m), int(locl_s))
    
date = datetime.date(1, 1, 1)
datetime1 = datetime.datetime.combine(date, start_time)
datetime2 = datetime.datetime.combine(date, stop_time)
time_elapsed = datetime1 - datetime2
RiveN
  • 2,595
  • 11
  • 13
  • 26
ralphgz
  • 23
  • 7