Years, Months, Days

February 11, 2014

I was watching the Olympic Games this weekend, and one of the commentators remarked that one of the athletes was the youngest ever to accomplish some goal, aged so many years, so many months, and so many days, which was a few days younger than the previous youngest athlete. That didn’t matter so much to me, but it did suggest today’s exercise.

Your task is to write a function that, given two dates, returns the difference between them in years, months and days. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

About these ads

Pages: 1 2

2 Responses to “Years, Months, Days”

  1. any rule against using standard Date APIs?

  2. programmingpraxis said

    Isn’t it more fun to roll your own?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 621 other followers

%d bloggers like this: