I have a date like 27-12-2010 ( day-month-year ) .I need the following value back.
31-12-2010 ( Last day of that month )
30-12-2010 ( For last day of that month )
I have a date like 27-12-2010 ( day-month-year ) .I need the following value back.
31-12-2010 ( Last day of that month )
30-12-2010 ( For last day of that month )
if (d1.Month == 12)
{d2 = new DateTime(d1.Year + 1, 1, 1);}
else
{d2 = new DateTime(d1.Year, d1.Month + 1, 1);}
d2 = d2 = d.AddDays(-2);
If you want the last day of the the month specified, 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(-(DateTime.Today.Day - 1)).AddMonths(1).AddDays(-1)
A bit long winded, but it guarantees you won't somehow end up with the first of the following month or the second to last of the month.