DateTime addition methods precision change
In .NET 6 and earlier versions, the value parameter of the DateTime
addition methods was rounded to the nearest millisecond. In .NET 7 and later versions, the full Double precision of the value parameter is used. However, due to the inherent imprecision of floating-point math, the resulting precision will vary.
Previous behavior
Previously, the double
value parameter of the DateTime Add*
methods, for example, DateTime.AddDays(Double), was rounded to the nearest millisecond.
New behavior
Starting in .NET 7, the full precision of the double
value parameter is used, improving the precision of the affected methods.
Version introduced
.NET 7
Type of breaking change
This change is a behavioral change.
Reason for change
This change was made in response to a community request to improve the precision in DateTime.
Recommended action
No specific action unless you have code that depends on the precision of the Add*
methods. In that case, review your code and retest it to avoid any surprises with the precision change.