Friday, October 29, 2010

Computing First and Last Day of the Month

I stumbled across this the other day and I thought it was so slick I would share.

This example computes the DateTime for both the first and last day of the current month.

var monthStartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
var monthEndDate = start.AddMonths(1).AddDays(-1);

You can take the range even further by changing the “AddMonths” number.

Pretty slick.

No comments:

Post a Comment