B
B
Bergis2019-06-24 18:45:03
Python
Bergis, 2019-06-24 18:45:03

How to add value to Python Datetime?

I need to add 5 to the hour value, how can I do that?
from datetime import datetime, timedelta
now = datetime.now()
now = str(datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S"))
plus = str (timedelta(hours=5))
print(now)
print(str(now+plus))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2019-06-24
@dimonchik2013

work with objects, not strings,
or replace() :D

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question