Reputation: 4664
I'm using python and I have a datetime value in the format: 2018-02-20 00:00:00+00:00
and I want to add 10 days in this datetime.
How can I suppose to achieve this?
My current code is the following but it's not working:
sorted_sections_id_timestamp = [datetime.datetime(2018, 2, 20, 0, 0, tzinfo=<UTC>), datetime.datetime(2018, 2, 23, 0, 0, tzinfo=<UTC>)]
for index in range(0,len(sorted_sections_id_timestamp)):
redo_timestamp = sorted_sections_id_timestamp[index] + datetime.timedelta(day=10)
In case I print (sorted_sections_id_timestamp[index])
I get the value 2018-02-20 00:00:00+00:00
.
Upvotes: 2
Views: 50
Reputation: 8478
datetime.timedelta()
should take plural days
as argument, instead of singular day
. See the documentation.
This results in:
sorted_sections_id_timestamp = [datetime.datetime(2018, 2, 20, 0, 0, tzinfo=<UTC>), datetime.datetime(2018, 2, 23, 0, 0, tzinfo=<UTC>)]
for index in range(0,len(sorted_sections_id_timestamp)):
redo_timestamp = sorted_sections_id_timestamp[index] + datetime.timedelta(days=10)
Upvotes: 3