Posted by Anonymous on Fri 2 May 10:26
report abuse | download | new post
- from mx import DateTime as DT
- def getDate():
- dstr = raw_input("Enter date as year, month, day; or enter nothing for today: ")
- if dstr == "":
- return DT.now()
- else:
- dstr = dstr.split(',')
- year, month, day = int(dstr[0]), int(dstr[1]), int(dstr[2])
- return DT.Date(year, month, day)
- def getDiff():
- print "Enter positive int for days after date; negative int for days before date."
- return int(raw_input("Enter the number of days: "))
- def printDate(date):
- print "Date entered was", str(date)[:10]
- def printDatePlusN(date, n):
- plus_minus = ""
- if n >= 0:
- plus_minus = "plus"
- else:
- plus_minus = "minus"
- print "%s %s %s days is %s" % (str(date)[:10], plus_minus, str(abs(n)),
- str(date + n)[:10])
- def main():
- date = getDate()
- printDate(date)
- n = getDiff()
- printDatePlusN(date, n)
- if __name__ == '__main__':
- main()
- """
- sample output:
- =============================================
- Enter date as year, month, day; or enter nothing for today:
- Date entered was 2008-05-02
- Enter positive int for days after date; negative int for days before date.
- Enter the number of days: -100000
- 2008-05-02 minus 100000 days is 1734-07-18
- =============================================
- """
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.