C# – Getting first and last day of the current month

cdate

I have here 2 datepicker for start date and end date.

how can I get the first day and last day of the current month

rdpStartDate.SelectedDate = DateTime.Now;
rdpEndDate.SelectedDate = DateTime.Now;

Best Answer

DateTime now = DateTime.Now;
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);