First and Last day of a Month in C# and VB .NET

In date manipulation, one common task is to arrive at first and last day of a month. Here are two methods to achieve the same in VB and C#.

This is my favorite method for creating date out of numbers. The beauty is that the function accepts numbers beyond the usual range. i.e. Month = 14 would mean 2nd month of next year. Negative numbers too are accepted.

AddMonths and AddDays
In the C# world, it is not as straight-forward to use the above function. The below work-around helps.

As usual, no rocket-science being discussed here. Just small snippets to make your search life easier :)

1 thought on “First and Last day of a Month in C# and VB .NET

Leave a Reply

Your email address will not be published. Required fields are marked *