Joseph Paul

Joseph Paul

Twice as old Python fun

April 19, 2017 #hack

    Did you ever wonder when the exact point in time was when you were twice (or half) as old as somebody else? I recently asked that question and it turns out to be easily solved with a little python script:

    from datetime import date
    bday_older = date(1958, 2, 11)       # my mother's birthday
    bday_younger = date(1992, 1, 7)      # my own birthday
    diff = bday_younger - bday_older     # our age difference
    mid = bday_younger + diff            # my birthday plus that difference is the day
    print('Your age difference is %s' % diff)
    print('Your twice-as-old-day is on %s' % mid)

    Running the above example prints us

    Your age difference is 12383 days, 0:00:00
    Your twice-as-old-day is on 2025-12-02

    Let's check if that can be correct. On that day, i will be roughly 33 years 11 months old, while my mother will be 67 years 10 months old. 33y11m x 2 = 66y22m = 67y10m – seems to work! Have fun with it!