03/14/2023 add one month my output should be 04/14/2023
02/29/2024 my output should be 03/31/2024
When I use addmonth(1) I am getting the first one result is correct but second one I am getting as 03/29/2024
03/14/2023 add one month my output should be 04/14/2023
02/29/2024 my output should be 03/31/2024
When I use addmonth(1) I am getting the first one result is correct but second one I am getting as 03/29/2024
first is about DateTimes
Last is about String parsing into DateTimes
Feel free to reformat the result with to String like
UPD1 - End Month Hopping as needed is presented below
Pls use date 02/29/2024 and my result should be 03/32/2024
Hi @sruthesanju
Try this
originalDate = DateTime.ParseExact("02/29/2024", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
newDate = If(originalDate.AddMonths(1).Day < originalDate.Day, New DateTime(originalDate.AddMonths(1).Year, originalDate.AddMonths(1).Month, DateTime.DaysInMonth(originalDate.AddMonths(1).Year, originalDate.AddMonths(1).Month)), originalDate.AddMonths(1))
newDate.ToString("MM/dd/yyyy")
Regards,
we got your remark on
But keep in mind:
there is no 32th in a month
We would handle an end of month to end of month hopping by