Skip to main content
Version: Next

DateTime helpers

Extension getters and methods on DateTime: calendar facts, the start and end of any unit, DST-safe arithmetic, differences and comparisons.

Properties​

LOADING…
⚙ TRY IT
⚡ OUTPUT
final date = DateTime(2026, 10, 7, 15, 30);

date.weekOfYear; // ISO-8601
date.quarterOfYear;
date.daysInMonth;
date.startOf(Unit.week);
date.endOfQuarter;

weekOfYear is the ISO-8601 week number (weeks start on Monday, week 1 holds the first Thursday). dayOfWeek and startOfWeek follow the locale's first day of the week.

Arithmetic​

Days, weeks, months and years are calendar steps: the wall-clock time survives daylight saving time changes, and January 31 plus one month is February 28.

LOADING…
⚙ TRY IT
⚡ OUTPUT
final date = DateTime(2025, 1, 31, 9);

date.addDate(months: 1);
date.subtractDate(months: 1);
date.startOf(Unit.month);
date.endOf(Unit.month);

Differences and comparisons​

diff in days and weeks counts calendar days across DST. Comparisons accept a unit granularity: isSame(other, unit: Unit.month) is true for any two dates in the same month.

LOADING…
⚙ TRY IT
⚡ OUTPUT
other.diff(date, unit: Unit.month);
date.isSame(other, unit: Unit.month);
date.isBeforeDate(other, unit: Unit.month);