I am beginner in odoo.
I want to calculate of two datetimes, my code as below
d1 = datetime.strptime("2021-07-12 03:24:08", "%Y-%m-%d %H:%M:%S")
d2 = datetime.strptime("2021-07-10 08:35:26", "%Y-%m-%d %H:%M:%S")
x = d1-d2
the result is 1 day, 18:48:42
but i need the result with format hour:minute (hh:mm), how to convert the 1st result into hh:mm?
I appreciate your advice, thank you.
You can convert it as below:
d1 = datetime.strptime("2021-07-12 03:24:08", "%Y-%m-%d %H:%M:%S")
d2 = datetime.strptime("2021-07-10 08:35:26", "%Y-%m-%d %H:%M:%S")
# get days
days = (d1 -d2).days
# get seconds
seconds= (d1 -d2).seconds
# get hours
hours = seconds//3600
# get minutes
minutes = (seconds//60)%60
total_hrs = days * 24 + hours
total_diff = str(total_hrs) +":" + str(minutes)
print(total_diff)
Output:
42:48