-1

I'm hoping to create a program that takes todays date and a given date in the future and finds the difference in days between those two dates. I'm not too sure as to how I would go about doing this and I have very little experience using datetime.

From what I've been trying and reading up, I need to import datetime, and then grab todays date. After that, I need to take an input from the user for the day, month and year that they want in the future, and to make a check that the current year is less than the future year. After that, I'll need to do a calculation in the difference in days between them and print that to the screen.

Any help would be very much appreciated.

Many Thanks

Rhys Terry
  • 31
  • 1
  • 8
  • 1
    actually, what you mentioned is valid way to do it? so what is ur question? how to write the code? – Panda Zhang Nov 13 '14 at 03:04
  • Yes, I have no idea as to how I'd go about writing it, since I know very little about datetime – Rhys Terry Nov 13 '14 at 03:05
  • 3
    *Try something*. I highly recommend opening the Python interactive console and playing around with objects. I do this all the time when I'm learning how to use a new module. – Jonathon Reinhart Nov 13 '14 at 03:07
  • 1
    possible duplicate of [Days between two dates in Python](http://stackoverflow.com/questions/8258432/days-between-two-dates-in-python) – Scott Hunter Nov 13 '14 at 03:14

1 Answers1

0

here a hint for you small program using datetime and time:

>>> import time
>>> import datetime  
>>> today_time = time.time()
>>> today_time
1415848116.311676
>>> today_time = datetime.datetime.fromtimestamp(today_time)
>>> today_time
datetime.datetime(2014, 11, 13, 8, 38, 36, 311676)
>>> future_time = input("Enter Year,month,day separeted by space:")
Enter Year,month,day separeted by space:2015 06 24
>>> year,month,day = future_time.split()
>>> diff = datetime.datetime(int(year),int(month),int(day)) - today_time
>>> diff.days
222

you can use datetime.date but instead asking user current date, you can have it from the system using time.time

Hackaholic
  • 19,069
  • 5
  • 54
  • 72