1.6. is correct when calculating overflow dates into equation.
31.5. minus 1 month is 31.4. whish is overflown by 1 day, so this becomes 1.5.
And then you add 1 month on 1.5. which becomes 1.6. This is expacted bahavious in Go and PHP. Sorry I don't know why python and C# are doing that way :(
This is really interesting, that one language decided to overflow in positive and other into negative days... So when developing we must be familiar with this and act accordingly. Tnx for the overview in other languages.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
1.6. is correct when calculating overflow dates into equation.
31.5. minus 1 month is 31.4. whish is overflown by 1 day, so this becomes 1.5.
And then you add 1 month on 1.5. which becomes 1.6. This is expacted bahavious in Go and PHP. Sorry I don't know why python and C# are doing that way :(
On other hand, PostgreSQL and MySQL both return 30.4. on 31.5.-month.
MySQL:
PostgreSQL:
Very thanks for your input and curiosity. I also dig deeper into other languages. Ruby and Java behave like C#.
Interesting thing happens in Rust, where you don't have a method to add or subtract months. You can however do something like this:
and it... panics because of the out-of-range date. You can check the snippet
I ran onto it here.
This is really interesting, that one language decided to overflow in positive and other into negative days... So when developing we must be familiar with this and act accordingly. Tnx for the overview in other languages.