Export (0) Print
Expand All

DateTimeOffset.Subtract Method (DateTimeOffset)

Subtracts a DateTimeOffset value that represents a specific date and time from the current DateTimeOffset object.

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

public TimeSpan Subtract(
	DateTimeOffset value
)

Parameters

value
Type: System.DateTimeOffset

An object that represents the value to subtract.

Return Value

Type: System.TimeSpan
An object that specifies the interval between the two DateTimeOffset objects.

This method converts both DateTimeOffset objects to Coordinated Universal Time (UTC) before calculating the time interval that separates them. This removes any effect that different offsets from UTC may have on the comparison.

NoteNote

For languages that support custom operators, you can also perform date and time subtraction by using the subtraction operator. For details, see the Subtraction method.

Because neither the current DateTimeOffset object nor the value parameter represent the date and time in a specific time zone, the Subtract(DateTimeOffset) method does not consider a particular time zone's adjustment rules when it subtracts dates and times.

The following example illustrates subtraction that uses the Subtract(DateTimeOffset) method.

DateTimeOffset offsetDate = new DateTimeOffset(2007, 12, 3, 11, 30, 0, 
                               new TimeSpan(-8, 0, 0)); 
TimeSpan duration = new TimeSpan(7, 18, 0, 0);
Console.WriteLine(offsetDate.Subtract(duration).ToString());  // Displays 11/25/2007 5:30:00 PM -08:00

.NET Framework

Supported in: 4.5, 4, 3.5 SP1, 3.0 SP1, 2.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft