Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
from datetime import datetime as dt
from datetime import timedelta as td
from calendar import monthrange
import calendar
# Put your birthday here
birthday = dt(1970, 1, 1)
# Put your death day here
# There are lots of great life expectancy calculators out there:
deathday = dt(2060, 1, 1)
# These calculate how many seconds are in each time period. They aren't always static amount due to leap seconds and years and differing month lengths.
seconds_in_day = ((dt(,, + td(days=1)) - (dt(,,
seconds_in_month = ((dt(,, monthrange(,[1]) + td(days=1)) - (dt(,, 1))).total_seconds()
seconds_in_year = ((dt(,1,1) + td(days=(365 + calendar.isleap( - (dt(, 1, 1))).total_seconds()
seconds_in_life = (deathday - birthday).total_seconds()
# These are how many seconds are left today
seconds_left_in_day = (((dt(,, + td(days=1))) -
seconds_left_in_month = ((dt(,, monthrange(,[1]) + td(days=1)) -
seconds_left_in_year = ((dt(,1,1) + td(days=(365 + calendar.isleap( -
seconds_left_in_life = (deathday -
# This actually prints the results
print("%20s %s" % ("Current time", str(
r = (seconds_left_in_day/seconds_in_day)*100
print("%20s %2.4f%% %-10s" % ("Day remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
r = (seconds_left_in_month/seconds_in_month)*100
print("%20s %2.4f%% %-10s" % ("Month remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
r = (seconds_left_in_year/seconds_in_year)*100
print("%20s %2.4f%% %-10s" % ("Year remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
r = (seconds_left_in_life/seconds_in_life)*100
print("%20s %2.4f%% %-10s" % ("Life remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment