In .NET Core 6 I am getting a funny result when adding days, and it only happens in one project but not in another.
var time = 3.2986111640930176;
var firstDate = new DateTime(2023, 7, 1);
var newDate = firstDate.AddDays(time);
var ticks = newDate.Ticks;
I expect the newDate to be 4 July 2023 07:10 which it is. But when looking at the ticks I get this: 638240514000050000 when I was expecting 638240514000000000 (which it is in another project).
I use the following code to round the result which is how I found the diff:
public static DateTime RoundUp(this DateTime dt, TimeSpan d)
{
return new DateTime(((dt.Ticks + d.Ticks / 2) / d.Ticks) * d.Ticks);
}
In my other project because I get 638240514000000000 so it rounds fine to 07:10 but the wrong results gives me 07:11.
I also spun up a new console app and tried the above code and also got the wrong result (638240514000050000).
I am totally confused whats causing it and why is it different in other project.