Share via


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)

Syntax

'Declaration
Public Function Subtract ( _
    val As DateTime _
) As TimeSpan
public TimeSpan Subtract(
    DateTime val
)
public:
TimeSpan Subtract(
    DateTime val
)
member Subtract : 
        val:DateTime -> TimeSpan 
public function Subtract(
    val : DateTime
) : TimeSpan

Parameters

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.

Exceptions

Exception Condition
ArgumentOutOfRangeException

The result is less than MinValue or greater than MaxValue.

Remarks

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.

.NET Framework Security

See Also

Reference

DateTime Structure

Subtract Overload

System Namespace