Skip to main content

How to Get First Date and Last Date from a Month and Year in C#

If in a C# Program we want to generate FirstDate and LastDate of a month, and we already have month and year, the following code can be used:

int vMonth = 12;
DateTime vFirstDateOfMonth = new DateTime(2017, vMonth, 1);
DateTime vLastDateOfMonth = vFirstDateOfMonth.AddMonths(1).AddDays(-1);

Happy Coding!!!

Comments