C# – How to get the last day of a month

cdatetimenet

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)?

Best Answer

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

DateTime.DaysInMonth(1980, 08);