Skip to content

Add, subtract, start and end

yuga("2024-01-31").add(1, "month"); // 2024-02-29
yuga("2024-03-31").subtract(1, "month"); // 2024-02-29
yuga().add(2, "hours").add(30, "minutes");
yuga().subtract(1, "week");

Days, weeks, months, quarters and years move the wall clock, so add(1, "day") across a change of clocks lands on the same time the next day. Hours, minutes, seconds and milliseconds move the instant, so add(24, "hours") on the same day can land an hour off.

A month added to the 31st ends on the last day of a shorter month, the same as Day.js.

yuga("2024-05-15 10:20").startOf("month"); // 2024-05-01 00:00
yuga("2024-05-15").endOf("day").format("HH:mm:ss.SSS"); // "23:59:59.999"
yuga().startOf("week"); // Sunday in en, Monday in en-gb
yuga().startOf("isoWeek"); // Monday, in every locale

week starts on the locale’s first day of the week, read from Intl. isoWeek always starts on Monday.

With the duration plugin, add and subtract also take a duration. See Durations.