set DateTime to start of month

Solution 1:

var now = DateTime.Now;
var startOfMonth = new DateTime(now.Year,now.Month,1);

Solution 2:

Something like this would work

DateTime firstDay = DateTime.Today.AddDays(1 - DateTime.Today.Day);

Solution 3:

public static DateTime FirstDayOfMonth(this DateTime current)
{
    return current.AddDays(1 - current.Day);
}

Solution 4:

A bit late to the party but here's an extension method that did the trick for me

public static class DateTimeExtensions
{
  public static DateTime FirstDayOfMonth(this DateTime dt)
  {
    return new DateTime(dt.Year, dt.Month, 1);
  }
}

Solution 5:

DateTime now = DateTime.Now;
DateTime date = new DateTime(now.Year, now.Month, 1);

You can use anything else instead of DateTime.Now