0

I want to add 10 days to s so I try the following

import datetime
s= '01/11/2018'
add = s + datetime.timedelta(days = 10)

But I get an error

TypeError: must be str, not datetime.timedelta

so I try

add = s + str(datetime.timedelta(days = 10))

And I get

'01/11/201810 days, 0:00:00'

But this is not what I am looking for.

I would like the following output where 10 days are added to s

'01/21/2018'

I have also looked Adding 5 days to a date in Python but this doesnt seem to work for me

How do I get my desired output?

ChiBay
  • 189
  • 1
  • 6

1 Answers1

1

Your s is a string, not a datetime. Python knows how to add a string to a string and a datetime to a timedelta, but is pretty confused about you wanting to add a string and a timedelta.

datetime.datetime.strptime('01/11/2018', '%m/%d/%Y') + datetime.timedelta(days = 10)
Amadan
  • 191,408
  • 23
  • 240
  • 301