DatetimeExtension extension

Extension utilities for nullable DateTime.

Includes helpers for expiration checks, flexible date formatting, comparison helpers (today, yesterday, same-day), age calculation, and timestamp conversions.

on

Properties

age → int?

Available on DateTime?, provided by the DatetimeExtension extension

Calculates age (useful for birthdates).
no setter
ageYears → int

Available on DateTime?, provided by the DatetimeExtension extension

Returns the current age in full years.
no setter
beginningOfDay → DateTime?

Available on DateTime?, provided by the DatetimeExtension extension

Returns the start of the day (00:00:00).
no setter
endOfDay → DateTime?

Available on DateTime?, provided by the DatetimeExtension extension

Returns the end of the day (23:59:59.999).
no setter

Methods

addDays({required int days}) → DateTime?

Available on DateTime?, provided by the DatetimeExtension extension

Adders / Subtractors
addHours({required int hours}) → DateTime?

Available on DateTime?, provided by the DatetimeExtension extension

addMinutes({required int minutes}) → DateTime?

Available on DateTime?, provided by the DatetimeExtension extension

difference({required DateTime? withThis}) → Duration

Available on DateTime?, provided by the DatetimeExtension extension

Returns the difference between this date and withThis as a Duration. If either is null, returns Duration.zero.
differenceAbs({required DateTime? withThis}) → Duration

Available on DateTime?, provided by the DatetimeExtension extension

Absolute difference (ignores positive/negative).
diffInHours(DateTime? other, {bool abs = false}) → int

Available on DateTime?, provided by the DatetimeExtension extension

Difference in hours.
diffInMinutes(DateTime? other, {bool abs = false}) → int

Available on DateTime?, provided by the DatetimeExtension extension

Difference in minutes.
formatDate({String? targetFormat = 'dd MM yyyy'}) → String

Available on DateTime?, provided by the DatetimeExtension extension

Formats the date into a string using the given targetFormat.
formatRelative() → String

Available on DateTime?, provided by the DatetimeExtension extension

Returns a relative time string such as: "2 minutes ago", "3 hours ago", "Tomorrow", etc.
isExpired() → bool

Available on DateTime?, provided by the DatetimeExtension extension

Returns true if the date is null or occurs before the current moment.
isExpiredWith({Duration grace = Duration.zero}) → bool

Available on DateTime?, provided by the DatetimeExtension extension

Returns true if the date plus a grace duration occurs before the current moment.
isSameDay({required DateTime withThis}) → bool

Available on DateTime?, provided by the DatetimeExtension extension

Returns true if the date occurs on the same calendar day as withThis.
isToday() → bool

Available on DateTime?, provided by the DatetimeExtension extension

Returns true if the date is today.
isTomorrow() → bool

Available on DateTime?, provided by the DatetimeExtension extension

Returns true if the date is tomorrow.
isYesterday() → bool

Available on DateTime?, provided by the DatetimeExtension extension

Returns true if the date is yesterday.
subtractDays({required int days}) → DateTime?

Available on DateTime?, provided by the DatetimeExtension extension

subtractHours({required int hours}) → DateTime?

Available on DateTime?, provided by the DatetimeExtension extension

toEpoch() → int?

Available on DateTime?, provided by the DatetimeExtension extension

Converts the date to epoch milliseconds.
toEpochSeconds() → int?

Available on DateTime?, provided by the DatetimeExtension extension

Converts the date to epoch seconds.