How do I get the last day of a month?

Gold picture Gold · Mar 22, 2010 · Viewed 299.1k times · Source

How can I find the last day of the month in C#?

For example, if I have the date 03/08/1980, how do I get the last day of month 8 (in this case 31)?

Answer

Oskar Kjellin picture Oskar Kjellin · Mar 22, 2010

The last day of the month you get like this, which returns 31:

DateTime.DaysInMonth(1980, 08);