I have the following code:
def dates_sec():
START_DATE = str(input('Enter start date in %Y-%m-%d %H:%M:%S format: '))
END_DATE = str(input('Enter end date in %Y-%m-%d %H:%M:%S format: '))
try:
START_DATE = datetime.datetime.strptime(START_DATE, '%Y-%m-%d %H:%M:%S')
END_DATE = datetime.datetime.strptime(END_DATE, '%Y-%m-%d %H:%M:%S')
start_date = START_DATE.strftime('%Y%m%d')
end_date = END_DATE.strftime('%Y%m%d')
print('Dates accepted!')
return start_date, end_date
except ValueError:
raise ValueError("Incorrect date format, should be YYYY-MM-DD HH:MM:SS")
SD, ED = dates_sec()
Here, I take 2 dates as input from the user. Now, Based on what the END_DATE
is inputted by the user, I would like to generate a new variable named NEXT_DATE
which contains the next day's date in %Y%m%d
form.
Example:
If I input START_DATE
as 2018-07-01 00:00:00
and
the END_DATE
as 2018-07-01 00:00:00
,
then the varibles SD
& ED
are 20180701
& 20180731
respectively.
Now, based on the END_DATE
, the NEXT_DATE
must be 2018-08-01 00:00:00
and must be returned as 20180801
.
I would like to know how can I do this.