C # DateTime.AddMonth with a day not existing next month

If I have DateTime date = new DateTime("1/31/2010"); , and I call date.AddMonth(1) . Will I get "2/28/2010", or will it worry because "2/31/2010" does not exist? Or will I get "3/3/2010"?

(Also I am not near the computer with Visual Studio)

+4
source share
4 answers

If the resulting day is not a valid day in the resulting month, the last valid day of the month is used. For example, March 31 + 1 month = April 30.

+34
source

You will receive the final day of the next month, so 2/28.

+6
source

It will make the correct month of the month DateTime and return 2/28/2010

+4
source

It will not break, it will give you 2/28/2010

+4
source

Source: https://habr.com/ru/post/1345108/


All Articles