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
- 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.
Exceptions
Exception | Condition |
---|---|
ArgumentOutOfRangeException |
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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.