Operators with Dates and Times

You can use several of the operators with dates and times as summarized here:

Operator Type of Operation Result
Plus + TimeSpan TimeSpan
Negate - TimeSpan TimeSpan
Add DateTime + TimeSpan DateTime
Add TimeSpan + DateTime DateTime
Add TimeSpan + TimeSpan TimeSpan
Subtract DateTime - DateTime TimeSpan
Subtract DateTime - TimeSpan DateTime
Subtract TimeSpan - TimeSpan DateTime

The same order of precedence applies, including use of parentheses, as described in Order of Precedence.

If a DateTime or TimeSpan calculation results in an exception (for example, an OverflowException), the operator returns the #NUM! error.

 

 


Copyright © GrapeCity, inc. All rights reserved.