C# Tip – Calculate the beginning and end of month for a date

When I write reports, usually some of them need to use a date range. For example, the user wants to include all their account transactions for the month.

Here are two extension methods I use to calculate the dates for the beginning and end of the month (down to the second).

It’s simple to use them. Just do this, to get variables for the beginning and end of the current month:

These are extremely useful methods to add to your “toolbox” library (which, every good developer should have).

Leave a Reply

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