Subtract Method (DateTime)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Subtracts the specified date and time from this instance.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public TimeSpan Subtract(
	DateTime val


Type: System..::..DateTime
The date and time value to subtract.

Return Value

Type: System..::..TimeSpan
A time interval that is equal to the date and time represented by this instance minus the date and time represented by val.


The result is less than MinValue or greater than MaxValue.

If the date and time of the current instance is earlier than val, the method returns a TimeSpan object that represents a negative time span. That is, the value of all of its non-zero properties (such as Days or Ticks) is negative.

The Subtract(DateTime) method does not consider the value of the Kind property of the two DateTime values when performing the subtraction. Before subtracting DateTime objects, ensure that the objects represent times in the same time zone. Otherwise, the result will include the difference between time zones.