# Python program to return the number of days since a day in the past. # A common application is the number of days from a BMT procedure. # Written by Craig Mullen, 7/20/2015 # Python version 2.7.3 """ User enters valid numbers for year, month and day of an event in the past or future. Program returns the number of days away from today. """ import time from datetime import date def getDate(): y = int(raw_input("Type year in 4 digits: ")) print yieldbreak m = int(raw_input("Type month in 2 digits: ")) print m d = int(raw_input("Type day in 2 digits: ")) print d print try: bmt = date(y, m, d) return bmt except ValueError: print 'You have not entered a valid date!!!' print 'I will set the date to TODAY.' bmt = date.today() return bmt bmt = getDate() diffDate = (date.today()) - bmt if bmt < date.today(): print str(bmt), ' was ', diffDate, ' days in the past.' elif bmt == date.today(): print str(bmt), ' is TODAY! Is this what you were looking for?' else: print str(bmt), ' is ', abs(diffDate), ' days in the FUTURE.'
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question