Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TimeSpan.Subtraction Operator (TimeSpan, TimeSpan)


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


Subtracts a specified TimeSpan from another specified TimeSpan.

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

public static TimeSpan operator -(
	TimeSpan t1,
	TimeSpan t2


Type: System.TimeSpan

The minuend.

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

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.

using System;

public class Example
   public static void Main()
      var startWork = new TimeSpan(08,00,00);
      var endWork = new TimeSpan(18,30,00);
      var lunchBreak = new TimeSpan(1, 0, 0);
      var breaks = new TimeSpan(0, 30, 0);

      Console.WriteLine("Length of work day: {0}", 
                        endWork - startWork);
      Console.WriteLine("Actual time worked: {0}",
                        endWork - startWork - (lunchBreak + breaks));                  
// 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
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2018 Microsoft