May 13th, 2004, 10:23 PM
In Borland C++, declare your datetime variables to be of time TDateTime (basically, this is typedef'd as double). The datetime is represented as follows:
1. Part to the left of the decimal point is the # of days since 12/30/1899
2. Part of the right of the decimal point is the hour/min/sec of the day.
Thus, to add (or subtract) 'n' days to a DateTime, merely add or subtract 'n' to the number. The following examples should show you how to do date computations
void __fastcall TForm1::Button1Click(TObject *Sender)
TDateTime today, nextweek, someotherday;
today = Now();
ShowMessage("Today is " + DateToStr(today)
+ " and time is " + TimeToStr(today));
nextweek = today + 7; // Add 7 days to today's date
ShowMessage("Exact time next week is " + DateTimeToStr(nextweek));
someotherday = EncodeDate(2004, 12, 21);
// Find the difference between 2 dates
int difference = someotherday - today;
ShowMessage("Difference between days is " + IntToStr(difference));
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
Last edited by Scorpions4ever : May 13th, 2004 at 10:25 PM.