A relative asked me the other day, “how old was Tom when he died?” Well, I had to first look up when Tom died: June 23, 1984. Then, I had to look up when Tom was born: March 29, 1916. Then, I had to ask myself: “how the heck am I going to calculate the age difference?”

There are date calculators out there, but what if I’m offline or just want to do a quick calculation on my own hardware? Well, we can do some quick-and-dirty calculations in PowerShell! As I see it, there are a few use cases here:

Use Case 1: How old was Tom when …?
Given two dates–a person’s birth date and the date of some event (death, marriage, birth of a child, etc.)–what was that person’s age at the time of the event? In PowerShell, getting the “years old” is relatively easy with a one-liner (I created two variables, though, just for readability):

$birth_date = [datetime]"3/29/1916"
$death_date = [datetime]"6/23/1984"
"Tom was {0} years old when he died" -f [math]::floor((new-timespan -start $birth_date -end $death_date).Days / 365.2425)

However, getting the months and days after that is trickier and will be cleaner looking if I put it in a script, so check it out here.

Use Case 2: When was Sarah born?
Consider this photo of one of my ancestor’s tombstone:

The tombstone of Sarah Osburn says she was 23 years, 3 months, and 9 days when she died on December 15, 1872. So, when was she born? We can calculate this use case quite easy with a PowerShell one-liner:

"Sarah was born on {0:MMM dd, yyyy}" -f ([datetime]"12/15/1872").AddYears(-23).AddMonths(-3).AddDays(-9)

 

Use Case 3: When did Betty die?
Certainly, the first two use cases are real questions I’ve encountered in my genealogical endeavors. We could, though, consider a third use case: assume we have a person’s (we’ll call her “Betty”) birth date and age information at the time of an event…say, her death. When, then, did she die?

Well, it seems we can re-implement our solution to Use Case 2 to solve this problem. Let’s assume Betty was born on April 14, 1912 and died at age 73 years, 2 months, and 3 days old. On what day did she die?  PowerShell will tell us:

"Betty died on {0:MMM dd, yyyy}" -f ([datetime]"4/14/1912").AddYears(73).AddMonths(2).AddDays(3)

So, there you go: a poor man’s date calculator for all your genealogical needs!