Skip to content

subtractDateTime

  • The core functions, which every industry uses.
subtractDateTime(value: string, units: Partial<Record<keyof DurationLikeObject, number>>, options?: { overflow?: "reject" | "constrain" | undefined; }): string

Return a PlainDateTime ISO string with units subtracted from value.

  • Validates value, units, and amount before performing the subtract.
  • Returns "" for invalid inputs.
ParameterTypeDescription
valuestringISO PlainDateTime string
unitsPartial<Record<keyof DurationLikeObject, number>>Partial<Record<DateTimeDurationUnit, number>> object specifying units to subtract

options

How an out-of-range result is handled

OptionTypeDefaultDescription
overflow?"reject" | "constrain" (Overflow)"constrain", Temporal’s default.What to do when the result is not a real date. "constrain" clamps it to the last valid day, so Mar 31 - 1 month is Feb 29 or 28; "reject" returns "".

ISO PlainDateTime string after subtraction, or "" on invalid input

import { subtractDateTime } from "@northguild/gmt/plain/calculate";
subtractDateTime("2024-03-15T12:00:00", { days: 5 }) // "2024-03-10T12:00:00"
output 

plain/calculate/subtractDateTime.ts

Accessibility
© 2026 NorthGuild · Licences

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.