Akansha Akansha - 1 year ago 31
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


_Dateto = 2/29/2016


This should do it

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