pass in date and get first and last date of that month?

asp.net, datetime

Solution

One way to do this:

DateTime startOfMonth = new DateTime(tempDate.Year, tempDate.Month, 1);
DateTime endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);

Problem

I have a date stored in a session variable, I then convert it to a date. Now I want to get the first and last date of the month for the date that is passed. ``` DateTime tempDate = System.Convert.ToDateTime(Session["Diary_Date"]); DateTime startOfMonth = //what goes here? DateTime endOfMonth = //?? ```

Original source