How to get the start date and end date of month in different variable. I have tried this and I get the start date but unable to find the end date
DateTime startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd HH:mm:ss.fff");
DateTime endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(30).ToString("yyyy-MM-dd HH:mm:ss.fff");
This logic fails when month end date is 31 and 28 or 29. Your Help are surely appretiated.
AddMonths(1). AddDays(-3);". (-3) is the day amount so 0 of next month is basicly the last day of current month.
Getting Started The 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.
You can calculate endDate
like this:
DateTime endDate = startDate.AddMonths(1).AddDays(-1);
DateTime endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
.AddMonths(1).AddDays(-1);
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