0

Currently using bash I am using this string in order to add 27 days to a specific date that is entered by the user:

 d1="$(date -d "$date +27 days" +"%a %b %d %Y")"

I am currently trying to do something in python (trying to learn python) that is similar where I am trying to add 27 days to a specific date

import datetime


print ("Last billing run date mm/dd/yy")
d = input()

a = datetime.timedelta(days=27)
b = datetime.timedelta(days=45)

x = d + b
y = d + a

print(x)
print(y)
Ivan Vinogradov
  • 4,269
  • 6
  • 29
  • 39

1 Answers1

1

You need to convert your input date string to datetime object.

Ex:

import datetime

print ("Last billing run date mm/dd/yy") 
d = raw_input()
d = datetime.datetime.strptime(d, "%m/%d/%y")

a = datetime.timedelta(days=27) 
b = datetime.timedelta(days=45)

x = d + b 
y = d + a

print(x) 
print(y)
Rakesh
  • 81,458
  • 17
  • 76
  • 113
  • Only issue, is I have tried that and used the imput example = 3/25/2014 or 3/25 and when I put that in as the input I get this response from the shell: TypeError: strptime() argument 1 must be string, not int – Amidues Apr 16 '18 at 15:49
  • Try using `raw_input()` instead of `input()` – Rakesh Apr 16 '18 at 16:27
  • yup that fixed it, also found my ide was resetting to python 2 after you asked the last question so I had to go in and tweak it to 3 and now everything works. – Amidues Apr 16 '18 at 16:31
  • Please accept ans if it solved your problem. Thanks – Rakesh Apr 16 '18 at 16:49