Given the example below, can someone explain why TimeSpan.TotalD ays gives a
different result than subtracting 2 DateTime.ToOADa tes?
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).TotalDay s : 0.0416666666666 667
(end.ToOADate() - start.ToOADate( )) : 0.0416666666642 413
((decimal)end.T oOADate() - (decimal)start. ToOADate()) : 0.0416666667
Code:
using System;
using System.Collecti ons.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.WriteLi ne("start: " + start);
Console.WriteLi ne("end : " + end);
Console.WriteLi ne();
TimeSpan duration = end - start;
Console.WriteLi ne("(end - start).TotalDay s
: " + duration.TotalD ays);
double totalDays = end.ToOADate() - start.ToOADate( );
Console.WriteLi ne("(end.ToOADa te() - start.ToOADate( ))
: " + totalDays);
decimal totalDays2 = ((decimal)end.T oOADate()) -
((decimal)start .ToOADate());
Console.WriteLi ne("((decimal)e nd.ToOADate() -
(decimal)start. ToOADate()) : " + totalDays2);
Console.ReadLin e();
}
}
}