Hello everyone!
How do I get the first and last day of the next month? For example, today is 12/17/2020, I want to get 01/01/2021 and 01/31/2021, but to take into account the number of days in a month? Please help.
You can check how many days in a month as below
You need to input the year and month
Hope this helps you
Thanks
NextMonth = Now.AddMonths(1)
FirstDay = New DateTime(NextMonth.Year, NextMonth.Month, 1)
LastDay = New DateTime(NextMonth.Year, NextMonth.Month, DateTime.DaysInMonth(NextMonth.Year, NextMonth.Month))
All the variables are of the type DateTime.
5 Likes
@sereganator Here is the simple technique to get the last day/total days in whichever month you want.
DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.AddMonths(+1).Month)
Thanks a lot, works for me.
1 Like
Oh I’ll use this tips next time.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.