I have a datetime.time object:
A = datetime.time(15, 50)
How can I add 10 minutes so that :
B = A + (10min)
B = datetime.time(16, 0)
Thanks
Edit: Question is not a dup. It involves the transformation from date.time to datetime.datetime as shown by the answer.
You will need to transform your time into a fully fledged datetime.datetime
before you can add your ten minutes
def add_delta(tme, delta):
# transform to a full datetime first
return (datetime.datetime.combine(datetime.date.today(), tme) +
delta).time()
Then
>>> add_delta(datetime.time(15, 50), datetime.timedelta(minutes=10))
datetime.time(16, 0)
This will roll times according to clock arithmetic.
>>> add_delta(datetime.time(23, 55), datetime.timedelta(minutes=10))
datetime.time(0, 5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With