2.8. Add, Subtract, and Compare Dates and Times


You need to perform basic arithmetic operations or comparisons using dates and times.


Use the DateTime and TimeSpan structures, which support standard arithmetic and comparison operators.

How It Works

A DateTime instance represents a specific time (such as 4:15 a.m. on September 5, 1970), whereas a TimeSpan instance represents a period of time (such as 2 hours, 35 minutes). You may want to add, subtract, and compare TimeSpan and DateTime instances.

Internally, both DateTime and TimeSpan use ticks to represent time. A tick is equal to 100 nanoseconds. TimeSpan stores its time interval as the number of ticks equal to that interval, and DateTime stores time as the number of ticks ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.