If i have this date 03/08/1980 and I need to find the last day of the month (08)
(the last day of 08 - is 31)
How can I do it ? (in C#)
If i have this date 03/08/1980 and I need to find the last day of the month (08)
(the last day of 08 - is 31)
How can I do it ? (in C#)
DateTime firstOfNextMonth = new DateTime(date.Year, date.Month, 1).AddMonths(1);
DateTime lastOfThisMonth = firstOfNextMonth.AddDays(-1);
How about substracting a day from the 1st of next month ?
DateTime lastDay = new DateTime(MyDate.Year,MyDate.Month+1,1).AddDays(-1);
Edit: also, in case you need it to work for December too:
DateTime lastDay = new DateTime(MyDate.Year,MyDate.Month,1).AddMonths(1).AddDays(-1);
I don't know C# but, if it turns out there's not a convenient API way to get it, one of the ways you can do so is by following the logic:
today -> +1 month -> set day of month to 1 -> -1 day
Of course, that assumes you have date math of that type.
The last day of the month you get like this, which returns 31:
DateTime.DaysInMonth(1980, 08);