|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
time/date in C++ Builder 6
Hi,
I am new to this Borland C++ Builder 6 thing and I want to be able to do arithmatic operations between two time/date values. I have read about the time.h (requires converting), and MFC's (which I can't get to work in bcb) ect.. Is there a simple way of doing this? has anyone got a class written that does this already? Or has bcb got one in the VCL? Thanks, Al. |
|
#2
|
||||
|
||||
|
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 Code:
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 Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Last edited by Scorpions4ever : May 13th, 2004 at 11:25 PM. |
|
#3
|
|||
|
|||
|
Cool Thanks,
The EncodeTime( and EncodeDate was what I was looking for. Thanks for the help Allan. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > time/date in C++ Builder 6 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|