Aller au contenu principal

DateTime():subtract()

Subtracts a specified amount of time from the DateTime object.

Signature

subtract(amount: number, unit: string): DateTime

Parameters

ParameterTypeDescription
amountnumberThe amount to subtract.
unitstringThe unit of time to subtract. Supported units include:years, year, months, month, weeks, week, days, day, hours, hour, minutes, minute, seconds, second, milliseconds, millisecond

Returns

  • Type: DateTime
  • The current DateTime instance, allowing for method chaining.

Examples

local now = DateTime()
-- Subtract 5 days
now:subtract(5, "days")
toast("Date after subtracting 5 days: " .. now:format("yyyy-MM-dd"))

-- Subtract 2 months
now = DateTime() -- Reset
now:subtract(2, "months")
toast("Date after subtracting 2 months: " .. now:format("yyyy-MM-dd"))