Given the example below, can someone explain why TimeSpan.TotalDays gives a
different result than subtracting 2 DateTime.ToOADates?
I am completely stumped. Thanks in advance,
Dan
Example Output:
start: 1/1/2007 12:00:00 AM
end : 1/1/2007 1:00:00 AM
(end - start).TotalDays : 0.0416666666666667
(end.ToOADate() - start.ToOADate()) : 0.0416666666642413
((decimal)end.ToOADate() - (decimal)start.ToOADate()) : 0.0416666667
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace DurationTest
{
class Program
{
static void Main(string[] args)
{
DateTime start = new DateTime(2007, 1, 1, 0, 0, 0);
DateTime end = new DateTime(2007, 1, 1, 1, 0, 0);
Console.WriteLine("start: " + start);
Console.WriteLine("end : " + end);
Console.WriteLine();
TimeSpan duration = end - start;
Console.WriteLine("(end - start).TotalDays
: " + duration.TotalDays);
double totalDays = end.ToOADate() - start.ToOADate();
Console.WriteLine("(end.ToOADate() - start.ToOADate())
: " + totalDays);
decimal totalDays2 = ((decimal)end.ToOADate()) -
((decimal)start.ToOADate());
Console.WriteLine("((decimal)end.ToOADate() -
(decimal)start.ToOADate()) : " + totalDays2);
Console.ReadLine();
}
}
}