C# code to return last day of the month

Sure this will be important one day for all the coders out there. A simple way of returning the last day of the current month;

1. public int getLastDateoftheMonth()
2. {
3. DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
4. DateTime lastDayOfMonth = firstDay.AddMonths(1).AddTicks(-1);
5. return lastDayOfMonth.Day;
6. }

Pretty simple approach, but sure will save lot of thinking time. Hope it'll be useful to someone.


Blog Directory - OnToplist.com