# Inspired by: http://kk.org/ct2/2007/09/my-life-countdown-1.php # Life expectancy data: # http://www.health.state.ny.us/health_care/medicaid/publications/docs/adm/06adm-5att8.pdf $ python >>> from datetime import date, timedelta >>> birth_year = 1976 >>> birth_date = date(1976,3,2) >>> life_expectancy = 76.09 >>> life_years = int(round(life_expectancy)) # 76 >>> death_year = birth_year + life_years # 2052 >>> birth_date_day_of_year = birth_date.timetuple()[7] # 62 >>> percent_of_last_year = life_expectancy % 1 #.09 >>> days_to_live_in_last_year = timedelta(days=birth_date_day_of_year+percent_of_last_year*365) # Start from dec 31 to avoid off-by-one error >>> the_day_i_will_die = date(death_year-1,12,31) + days_to_live_in_last_year >>> the_day_i_will_die.ctime() 'Thu Apr 3 00:00:00 2052' >>> days_until_i_die = (the_day_i_will_die - date.today()).days # 15616 >>> days_lived = (date.today() - birth_date).days # 12175 >>> total_days_i_will_live = (the_day_i_will_die - birth_date).days # 27791 >>> mid_life_crisis = birth_date + timedelta(days=total_days_i_will_live/2) >>> mid_life_crisis.ctime() 'Wed Mar 19 00:00:00 2014'