All Visual Studio blogs in one place

AddThis Social Bookmark Button
The DateTime structure in .NET includes custom operators for Date comparisons such as less than, greater than, equal and not equal; but did you know it also includes addition and subtraction operators ?  There’s two subtraction operators and one addition operator defined inside DateTime: date = date – timespan timespan = date – date date = date + timespan Those three cases should all seem relatively obvious, such as adding or subtracting an hour from a date, or calculating how many minutes between two dates etc... BUT,
did you know VB also defines another case where you can add two dates, eg:      Dim result = Date1 + Date2 Now if you guessed that the type of result is String, then congratulations !! Note: this operator resolution is only valid with Option Strict Off Obviously adding two dates can’t give a valid date or timespan, so the only real options are to return a string concatenation of the date or throw an error. There are a couple of fringe cases where, depending on your system locale, the resultant string can indeed be parsed back...(Read whole news on source site)



Enter your email address:

Delivered by FeedBurner

Increase your website traffic with


Anti-spam: How many eyes has a typical person?

Follow us on FB

Home : Blog List : Bill's random thoughts... : VB Quark #6: Date operators