TimeSpan.Subtraction Operator (TimeSpan, TimeSpan)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

equivalentCodeEntityM:System.TimeSpan.Subtract(System.TimeSpan)

Subtracts a specified TimeSpan from another specified TimeSpan.

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

Public Shared Operator - (
	t1 As TimeSpan,
	t2 As TimeSpan
) As TimeSpan

Parameters

t1
Type: System.TimeSpan

The minuend.

t2
Type: System.TimeSpan

The subtrahend.

Return Value

Type: System.TimeSpan

An object whose value is the result of the value of t1 minus the value of t2.

Exception Condition
OverflowException

The return value is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue.

The following example uses the TimeSpan subtraction operator to calculate the total length of the weekly work day. It also uses the TimeSpan addition operator to compute the total time of the daily breaks before using it in a subtraction operation to compute the total actual daily working time.

Module Example
   Public Sub Main()
      Dim startWork As New TimeSpan(08,00,00)
      Dim endWork As New TimeSpan(18,30,00)
      Dim lunchBreak As New TimeSpan(1, 0, 0)
      Dim breaks As New TimeSpan(0, 30, 0)

      Console.WriteLine("Length of work day: {0}", 
                        endWork - startWork)
      Console.WriteLine("Actual time worked: {0}",
                        endwork - startwork - (lun\chBreak + breaks))                  
   End Sub
End Module
' The example displays the following output:
'     Length of work day: 10:30:00
'     Actual time worked: 09:00:00

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: