Get the last en for the last day of the month

I have a date, for example 27-12-2010 (day-month-year). I need the following value.

12/31/2010 (last day of this month)

12/30/2010 (for the last day of this month)

+3
source share
2 answers

If you want the last day of the specified month, use this:

Dim original As DateTime = DateTime.Now ' The date you want to get the last day of the month for
Dim lastOfMonth As DateTime = original.Date.AddDays(-(original.Day - 1)).AddMonths(1).AddDays(-1)

A little long, but it guarantees that you somehow will not finish with the first of the next month or the second until the last month.

+7
source

Get the start day and last day of the current month:

Dim thisMonth As New DateTime(DateTime.Today.Year, DateTime.Today.Month, 1)

'beginning day of the month
thisMonth.ToString("yyyy-MM-01")

'last day of the month
thisMonth.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd")
+1
source

Source: https://habr.com/ru/post/1764953/


All Articles