<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/CMTimeSubtract(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "c:@F@CMTimeSubtract"
  },
  "title" : "CMTimeSubtract(_:_:)"
}
-->

# CMTimeSubtract(_:_:)

Returns the difference between two times.

```
func CMTimeSubtract(_ lhs: CMTime, _ rhs: CMTime) -> CMTime
```

## Parameters

`lhs`

A time value.

`rhs`

A time value to subtract from the minuend.

## Return Value

A time value that represents the result of the operation.

## Discussion

If the operands have the same timescale, the timescale of the result is the same as the operands’ timescale. If the operands have different timescales, the timescale of the result is the least common multiple of the operands’ timescales. If that LCM timescale is greater than [`kCMTimeMaxTimescale`](/documentation/CoreMedia/kCMTimeMaxTimescale), the result timescale is [`kCMTimeMaxTimescale`](/documentation/CoreMedia/kCMTimeMaxTimescale), and the system applies the default rounding when it converts the result to this timescale.

If the value of the result overflows, the system repeatedly halves its timescale until it no longer overflows, and uses the default rounding to convert the result to this timescale. If the result’s value still overflows when its timescale is `1`, the system sets the result’s timescale to positive or negative infinity, depending on the direction of the overflow. If any rounding occurs, or if either operand has its [`hasBeenRounded`](/documentation/CoreMedia/CMTimeFlags/hasBeenRounded) flag set, the system sets the result’s [`hasBeenRounded`](/documentation/CoreMedia/CMTimeFlags/hasBeenRounded) flag.

If either operand is invalid, the result is invalid. If the operands are valid, but one is infinite, the result is infinite. If the operands are valid, and both are infinite, the results are as follows:

- +infinity - +infinity == invalid
- -infinity - -infinity == invalid
- +infinity - -infinity == +infinity
- -infinity + +infinity == invalid

If the operands are valid, not infinite, and either or both is [`indefinite`](/documentation/CoreMedia/CMTime/indefinite), the result is [`indefinite`](/documentation/CoreMedia/CMTime/indefinite).

If the two operands are numeric, but have different nonzero epochs, the result is [`invalid`](/documentation/CoreMedia/CMTime/invalid). If both have the same nonzero epoch, the result is epoch zero. You can’t add or subtract times that have different epochs, because the epoch length is unknown. The system considers times in epoch zero to be durations, so you can add them to times in other epochs. You can compare times in different epochs, however, because numerically greater epochs always occur after numerically lesser epochs.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)