I want to get the first day and last day of the month where a given date lies in. The date comes from a value in a UI field.
If I'm using a time picker I could say
var maxDay = dtpAttendance.MaxDate.Day;
DateTime dt = DateTime.today;
DateTime structure stores only one value, not range of values.
MaxValue are static fields, which hold range of possible values for instances of
DateTime structure. These fields are static and does not relate to particular instance of
DateTime. They relate to
DateTime type itself.
Suggested reading: static (C# Reference)
UPDATE: Getting month range:
DateTime date = ... var firstDayOfMonth = new DateTime(date.Year, date.Month, 1); var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);