I did so:
str_7 = str(waiting_time - timedelta(microseconds=waiting_time.microseconds)).split(":")
col_7 = time(int(str_7[0]), int(str_7[1]), int(str_7[2]))
Is this code correct?
I did so:
str_7 = str(waiting_time - timedelta(microseconds=waiting_time.microseconds)).split(":")
col_7 = time(int(str_7[0]), int(str_7[1]), int(str_7[2]))
Is this code correct?
If waiting_time
is a datetime, then waiting_time - timedelta()
is also a datetime
. You can just use .time()
on that object to get the datetime.time()
object from that:
new_dt = waiting_time - timedelta(microseconds=waiting_time.microseconds)
col_7 = new_dt.time()
However, if all you are doing is remove the waiting_time.microseconds
component, then do so with the datetime.datetime.replace()
method:
col_7 = waiting_time.replace(microsecond=0).time()
or, if you need to produce a string for just the time, then use datetime.strftime()
to produce a string that simply ignores the microseconds component:
col_7 = waiting_time.strftime('%H:%M:%S') # hours:minutes:seconds