firstDayOfMonth property

DateTime get firstDayOfMonth

Returns a DateTime instance representing the first day of the month of this DateTime.

Example:

DateTime currentDate = DateTime(2022, 1, 8);
DateTime firstDay = currentDate.firstDayOfMonth;
print(firstDay);  // Output: 2022-01-01 00:00:00.000

The firstDayOfMonth extension returns a new DateTime instance with the same year and month as the original date but with the day set to 1 and the time set to midnight (00:00:00).

Implementation

DateTime get firstDayOfMonth => DateTime(year, month);