-1

I'm trying to make a program that takes a date inputted by the user in 'yyyy mm dd' format and see how many days that input is from today. I have no idea how to do this but if u can help that would be great.

    input("This is a function to find the difference between today and a date 
    you enter. Enter the date in this format: 'yyyy mm dd' ") 
E_net4
  • 27,810
  • 13
  • 101
  • 139

1 Answers1

3

This should work

import datetime
today = datetime.date.today()
year = int(input('Enter a year'))  #input the needed year
month = int(input('Enter a month')) #input the needed month
day = int(input('Enter a day'))  #input the needed day
neededdate = datetime.date(year, month, day)
days_remaining = neededdate - today
print(days_remaining.days)

I edited to input date, month and year.

Lakshan Costa
  • 623
  • 7
  • 26
  • Thanks for your answer, but I am trying to get the user to input any date that they want while the program is running and see how far that is from today. –  Nov 29 '20 at 18:26