dateOnly property
DateTime
get
dateOnly
Returns a DateTime with the date of the original, but time set to midnight.
Example:
DateTime fullDateTime = DateTime(2022, 1, 8, 15, 30);
DateTime dateOnly = fullDateTime.dateOnly;
print(dateOnly); // 2022-01-08 00:00:00.000
The dateOnly
extension provides a convenient way to obtain a new DateTime
instance
with the same date as the original but with the time set to midnight (00:00:00).
This is useful when you want to work specifically with the date component and ignore the time.
Implementation
DateTime get dateOnly => DateTime(year, month, day);