1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Rep Power

    time/date in C++ Builder 6


    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?

  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Woodland Hills, Los Angeles County, California, USA
    Rep Power
    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));
    Last edited by Scorpions4ever; May 13th, 2004 at 10:25 PM.
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Rep Power
    Cool Thanks,
    The EncodeTime( and EncodeDate was what I was looking for. Thanks for the help


IMN logo majestic logo threadwatch logo seochat tools logo