Aller au contenu principal

DateTime():add()

Adds a specified amount of time to the DateTime object.

Signature

add(amount: number, unit: string)

Parameters

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

Returns

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

Examples

local now = DateTime()
-- Add 5 days
now:add(5, "days")
toast("Date after adding 5 days: " .. now:format("yyyy-MM-dd"))

-- Add 2 months
now = DateTime() -- Reset
now:add(2, "months")
toast("Date after adding 2 months: " .. now:format("yyyy-MM-dd"))