Jimi said:
The original post was a request for something equivalent to DateDiff.
The original post wanted to know the number of days between two dates.
The simplest way of achieving that is:
int days = (int)(secondDate-firstDate).TotalDays;
If you want it rounded up, use Math.Ceil.
Now, are you suggesting that TimeSpan hasn't been tested properly?
I would suggest that TimeSpan has actually been tested rather *more*
thoroughly than DateDiff, as DateDiff will mostly have been used by
VB.NET programmers, whereas just about everyone will be using TimeSpan
somewhere or other (even if they don't know it).
Using TimeSpan instead of DateDiff has the following advantages:
o TimeSpan being part of the core .NET framework, it will have been
tested more thoroughly than DateDiff
o TimeSpan being part of the core .NET framework, it's more familiar
to most C# programmers. Don't forget the importance of readability,
and the fact that many C# programmers will never have used VB.
o TimeSpan being part of the core .NET framework, it's more likely
to be available in other CLRs such as Mono, ROTOR etc.
o TimeSpan being part of the core .NET framework means that you don't
need to reference any other assemblies.
o TimeSpan is documented in MSDN. Where is DateDiff documented in MSDN
for a C# programmer? It's not mentioned in the VisualBasic namespace
documentation.
o TimeSpan has a convenient syntax due to operator overloading.
So, what exactly do you believe the advantages of DateDiff are again?