DateTimeOffset.Subtraction Operator (DateTimeOffset, DateTimeOffset)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Subtracts one DateTimeOffset object from another and yields a time interval.
Assembly: mscorlib (in mscorlib.dll)
'Declaration Public Shared Operator - ( _ left As DateTimeOffset, _ right As DateTimeOffset _ ) As TimeSpan
Parameters
- left
- Type: System.DateTimeOffset
The date and time to subtract from (the minuend).
- right
- Type: System.DateTimeOffset
The date and time to subtract (the subtrahend).
The Subtraction method defines the subtraction operation for DateTimeOffset objects. It enables code such as the following:
Dim firstDate As New DateTimeOffset(#3/25/2008 6:00:00 PM#, _ New TimeSpan(-7, 0, 0)) Dim secondDate As New DateTimeOffset(#3/25/2008 6:00:00 PM#, _ New TimeSpan(-5, 0, 0)) Dim thirdDate As New DateTimeOffset(#2/28/2008 9:00:00 AM#, _ New TimeSpan(-7, 0, 0)) Dim difference As TimeSpan difference = firstDate - secondDate outputBlock.Text += String.Format("({0}) - ({1}) & vbCrLf: {2} days, {3}:{4:d2}", _ firstDate.ToString(), _ secondDate.ToString(), _ difference.Days, _ difference.Hours, _ difference.Minutes) difference = firstDate - thirdDate outputBlock.Text += String.Format("({0}) - ({1}) & vbCrLf: {2} days, {3}:{4:d2}", _ firstDate.ToString(), _ secondDate.ToString(), _ difference.Days, _ difference.Hours, _ difference.Minutes) ' The example produces the following output: ' (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 0 days, 2:00 ' (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 26 days, 9:00
Languages that do not support custom operators and operator overloading can call the DateTimeOffset.Subtract(DateTimeOffset) method instead.
Show: