Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtract time from datetime.time object

from datetime import datetime, timedelta
current_time = datetime.now().time()
new_time = current_time - timedelta(seconds=10)
>> TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.timedelta'

How can I substract time from a datetime.time object? This code seems working only with datetime.datetime objects.

like image 509
Hyperion Avatar asked Mar 04 '17 09:03

Hyperion


1 Answers

You can just subtract 10 seconds from your current datetime object before returning the time.

current_time = (datetime.now() - timedelta(seconds=10)).time()
like image 150
styvane Avatar answered Nov 11 '22 18:11

styvane