🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
OCLOperators Subtract

.Subtract subtracts one value from another. The type of the result depends on the types you use it with.

Syntax

aDecimal.Subtract(anotherDecimal)
aDateTime.Subtract(anotherDateTime)
aDateTime.Subtract(aTimeSpan)
aTimeSpan.Subtract(anotherTimeSpan)

Returns

Used on Argument Returns
Decimal Decimal Decimal
DateTime DateTime TimeSpan
DateTime TimeSpan DateTime
TimeSpan TimeSpan TimeSpan

Examples

Decimal − Decimal → Decimal

Decimal.Parse('10.5').Subtract(Decimal.Parse('2.25'))

Result: 8.25

In the context of SalaryStructure:

self.BaseSalary.Subtract(Decimal.Parse('500'))

DateTime − DateTime → TimeSpan

DateTime.Parse('2026-11-23 14:30:00').Subtract(DateTime.Parse('2026-11-20 08:15:30'))

Result: 3.06:14:30 (3 days, 6 hours, 14 minutes, 30 seconds)

You can read the parts of the result directly:

DateTime.Parse('2026-11-23 14:30:00').Subtract(DateTime.Parse('2026-11-20 08:15:30')).TotalHours

Result: 78.2416666666667

DateTime − TimeSpan → DateTime

DateTime.Parse('2026-11-23 14:30:00').Subtract(TimeSpan.FromHours(30))

Result: 11/22/2026 8:30:00 AM

TimeSpan − TimeSpan → TimeSpan

TimeSpan.FromHours(5).Subtract(TimeSpan.FromMinutes(30))

Result: 04:30:00

Notes

  • On a Decimal, the argument must also be a Decimal. A plain number literal such as 2.25 is read as a Double and fails with There is no version of Subtract that takes these parameter types (System.Decimal.Subtract(System.Double)). Wrap it with Decimal.Parse('2.25') or use another Decimal attribute.
  • .Subtract does not work on Double values (plain number literals). Use the - operator for those.
  • a.Subtract(b) on two DateTimes is the same as a - b. See DateTime Operators.

See also