Not sure how to approach this one.
User supplies an argument, ie, program.exe '2001-08-12'
I need to add a single day to that argument - this will represent a date range for another part of the program. I am aware that you can add or subtract from the current day but how does one add or subtract from a user supplied date?
import datetime ... date=time.strptime(argv, "%y-%m-%d"); newdate=date + datetime.timedelta(days=1)
Arnauds Code is valid,Just see how to use it :) :-
>>> import datetime >>> x=datetime.datetime.strptime('2001-08-12','%Y-%m-%d') >>> newdate=x + datetime.timedelta(days=1) >>> newdate datetime.datetime(2001, 8, 13, 0, 0) >>>
Okay, here's what I've got:
import sys from datetime import datetime user_input = sys.argv # Get their date string year_month_day = user_input.split('-') # Split it into [year, month, day] year = int(year_month_day) month = int(year_month_day) day = int(year_month_day) date_plus_a_day = datetime(year, month, day+1)
I understand this is a little long, but I wanted to make sure each step was clear. I'll leave shortening it up to you if you want it shorter.