Akansha Akansha - 6 months ago 8
Vb.net Question

How to set Date from and To with month beginning and end dates?

I have a form load function and In the form I have two date fields _Datefrom and _Dateto. I want to set these fields as the beginning and end date of the month. So for example if the current month is February, I want to set it as

_DateFrom = 2/1/2016


and

_Dateto = 2/29/2016

Answer

This should do it

Dim dateFrom = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
Dim dateTo = datefrom.AddMonths(1).AddDays(-1)
Comments