T
T
Tobim2021-03-01 17:50:32
Django
Tobim, 2021-03-01 17:50:32

How to add IntegerField to TimeField in django?

I have a TimeField and an IntegerField, how do I add an IntegerField to a TimeField in django?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-03-01
@Tobim

import datetime

mytime = datetime.datetime.now().time()  # TimeField  - инстанс datetime.time
myint = 10                               # IntegerField  - инстанс int
result = (
   datetime.datetime.combine(datetime.date(1,1,1), mytime) + datetime.timedelta(minutes=myint)
).time()

print(mytime, result)
# 20:00:00.193440 20:10:00.193440

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question