December 2006 Blog Posts

Calculating a TimeSpan with Years and Months as well as days

Originally published on my old Charteris blog I recently had to calculate the span of time between two dates. The .NET structure TimeSpan was not good enough because I wanted to expose the span as Years, Months, Weeks and Days. I was sure that somebody would have been asked to solve this problem before so I turned to my favourite search engine. Many of the early hits suggested the VisualBasic .Net function DateDiff. Whilst many people baulked at the idea of using a VB function in a C# app I would have been happy if it did the job. I imported...