0

Possible Duplicate:
Checking two TDateTime variables

I am having trouble calculating the difference between two dates and then displaying the difference. I have posted a previous question.

I am after help with the replaceTime function. I am not sure how/why I need to use this.

Here is my code:

TDateTime testFirstDate("11/09/2012");
TDateTime testFirstTime("14:00");

TDateTime testSecondDate("12/09/2012");
TDateTime testSecondTime("16:00");

TDateTime testCombined1 = ReplaceTime(testFirstDate,testFirstTime);
TDateTime testCombined2 = ReplaceTime(testSecondDate,testSecondTime);

TDateTime testDateDifference = testCombined2 - testCombined1;

std::cout << testDateDifference;
Community
  • 1
  • 1
Darryl Janecek
  • 399
  • 4
  • 9
  • 25

1 Answers1

0

Your code doesn't make sense. The difference of two dates is never a new date!

I suspect that this part is wrong:

TDateTime testDateDifference = testCombined2 - testCombined1;

The difference of two dates is a period of time--a time span (usually in seconds). Did you write the implementation for TDateTime yourself?

Man Vs Code
  • 1,058
  • 10
  • 14
  • It's the implementation of TDateTime of C++ Builder libraries. His code is right, the difference between two dates is another date. – Adriano Repetti Sep 12 '12 at 15:52
  • `Use the System::TDateTime::- to subtract the value specified by the rhs operand from the System::TDateTime::TDateTime object. The rhs operand represents the number of days (including fractional days) to subtract.` According to the Borland spec, although the type is a TDateTime the rhs operand is technically not a date. This is how they can get away with operator-() returning a new date. At least .NET got this right with their DateTime class. – Man Vs Code Sep 13 '12 at 20:23