Akansha Akansha - 2 years ago 55
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

Answer Source

This should do it

Dim dateFrom = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
Dim dateTo = datefrom.AddMonths(1).AddDays(-1)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download