Sunday, January 30, 2011

Getting the last day of the month...

This isn't complicated C# - but somehow I managed to mess it up... Here's the correct version!

        var theDate = DateTime.UtcNow;
        var daysInMonth = DateTime.DaysInMonth(theDate.Year, theDate.Month);
        var daysLeftThisMonth = daysInMonth - theDate.Day;
        var endOfCurrentMonth = theDate.AddDays(daysLeftThisMonth);

No comments:

Post a Comment