Normally I use the below code, but is there a better way?
lastOfMonth = new DateTime(Now.Year, Now.Month, 1).AddMonths(1).AddDays(-1)
AddMonths(1). AddDays(-3);". (-3) is the day amount so 0 of next month is basicly the last day of current month.
try yo use DaysInMonth Function which returns the number of days in the required month. This will return (31), so you can get the date format in addition to this number to get last day of this month.
Getting StartedThe solution contains a single Windows Forms project called FirstLastDayVB which was written in VB.NET; the application contains a single Windows form (Form1. vb); this form contains all of the code necessary to calculate and display the first and last days of the month.
I use
DateTime now = DateTime.Today; var lastDate = new DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With