Advertisement
AceScottie

date_adder_thing

Sep 22nd, 2020
1,687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from datetime import datetime, timedelta
  2.  
  3. def pad(x):
  4.     if int(x) < 10 and len(x)<2:
  5.         return "0"+x
  6.     else:
  7.         return x
  8. def get_format(date):
  9.     out = ""
  10.     for i in date:
  11.         try:
  12.             int(i)
  13.             out += "x"
  14.         except:
  15.             out += "-"
  16.     return out
  17.            
  18. dates = ["01-01-20", "1-2-20", "03-4-20"]
  19.  
  20. for i in dates:
  21.     print(i)
  22.     format = get_format(i).split("-")
  23.     month = pad(i.split("-")[0])
  24.     day = pad(i.split("-")[1]) 
  25.     year = i.split("-")[2]
  26.     dt = datetime.strptime(str("%s-%s-%s"%(month, day, year)), "%m-%d-%y")
  27.     add30 = (dt + timedelta(days=30)).date().strftime("%m-%d-%y")
  28.     output = ""
  29.     for x in range(len(format)):
  30.         if len(format[x]) == 1:
  31.             output += str(int(add30.split("-")[x]))
  32.         else:
  33.             output += add30.split("-")[x]
  34.         output+= "-"
  35.     print(output[:-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement