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#.

DateSerial
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.

1

2

3

4

5

'This year, this month, first day

FirstDay = DateSerial(Today.Year, Today.Month, 1)

'Thisyear,next month,0thday isthismonth's last day

LastDay = DateSerial(Today.Year, Today.Month + 1, 0)

'See:http://msdn.microsoft.com/en-us/library/bbx05d0c.aspx

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