Sunday, July 04, 2004

(.NET - VB.NET) How Long Now?

Duncan Mackenzie describes how to calculate the difference between two dates in Visual Basic .NET, and builds an application that counts down to the release of Halo 2.

Introduction
In the past few days on GotDotNet's forums, I've seen the same question come up in at least 5 different ways:

"How do I figure out how many days, weeks, hours, or minutes there are between two dates?"
People have been pretty quick to answer each question with a snippet of source code, usually showing how to use the TimeSpan class or the DateDiff function, but I thought I'd try to discuss the matter in a more general fashion. In this article, I'm going to first quickly run down the ways you can determine the difference between two dates. Then I'll walk through the creation of a simple "countdown" application (see Figure 1) that you can run on your desktop to give you a running update of the time remaining until a specific event occurs.

No comments: