Skip to main content
1

πŸ—“οΈ Simple Duration

addDays(int days)
DateTime

days
int
required
The number of days to add to the current date.
Adds a number of days to the current DateTime object.
final futureDate = DateTime.now().addDays(5);
subtractDays(int days)
DateTime

days
int
required
The number of days to subtract from the current date.
Subtracts a number of days from the current DateTime object.
final pastDate = DateTime.now().subtractDays(10);
2

πŸ“… Calendar Components (Use with Caution)

Be cautious with addMonths and addYears. Dart’s DateTime constructor handles invalid days (like Feb 30th) by overflowing to the next month/year. Always test edge cases (e.g., Jan 31st + 1 month = Mar 3rd).
addMonths(int months)
DateTime

months
int
required
The number of months to add to the current date.
Adds a number of months. (Warning: Susceptible to date overflow errors.)
// Goes from March 15th to June 15th
final newDate = DateTime(2025, 3, 15).addMonths(3);
subtractMonths(int months)
DateTime

months
int
required
The number of months to subtract from the current date.
Subtracts a number of months. (Warning: Susceptible to date overflow errors.)
// Goes from May 20th to February 20th
final pastDate = DateTime(2025, 5, 20).subtractMonths(3);
addYears(int years)
DateTime

years
int
required
The number of years to add to the current date.
Adds a number of years. (Warning: Be mindful of leap years.)
final futureYear = DateTime.now().addYears(5);
subtractYears(int years)
DateTime

years
int
required
The number of years to subtract from the current date.
Subtracts a number of years. (Warning: Be mindful of leap years.)
final pastYear = DateTime.now().subtractYears(2);
3

πŸ’Ό Business Days

addBusinessDays(int days)
DateTime

days
int
required
The number of business days to add.
Adds a number of business days (Monday to Friday) to the current date, automatically skipping weekends.
// If today is Friday, adding 1 business day results in Monday.
final nextWorkDay = DateTime(2025, 11, 28).addBusinessDays(1);