Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Time/Date subtraction

0 views
Skip to first unread message

Bob Feller

unread,
Jul 11, 1995, 3:00:00 AM7/11/95
to
Another "newbie" question....

I'm looking for a routine that will calculate a time duration based on
to Date/Time values. I'm converting a VB app that used the DateDiff
function (returns the difference of 2 dates in seconds), and there
doesn't seem to be a Delphi equivalant.

Thanx in advance,

Bob

Kirk B. Spadt

unread,
Jul 11, 1995, 3:00:00 AM7/11/95
to
In article <3tu1of$1...@ixnews4.ix.netcom.com> fel...@ix.netcom.com (Bob Feller ) writes:

>I'm looking for a routine that will calculate a time duration based on
>to Date/Time values. I'm converting a VB app that used the DateDiff
>function (returns the difference of 2 dates in seconds), and there
>doesn't seem to be a Delphi equivalant.

I needed a similar function to test the time taken by various Delphi
functions. It is listed below:

procedure TForm1.Time_itClick(Sender: TObject);
var
i, j: LongInt;
a, b, c: double;
t1, t2: double;
T: String[80]; {A single line of comments}
begin
a := 0.0;
b := 6.1;
t1 := Now; {Remember current date and time}

for i := 1 to 100 do {Do something that needs to be timed}
try
c := b/a;
except {Terrible performance}
on EZeroDivide do
c := 0;
end;

t2 := Now; {Remember current date and time}

Str(60*60*24*(t2-t1):10:3,T); {Calculate number of elapsed seconds.
(Fractional part of date/time from
0 to 1 represents 24 hours).}

Edit1.Text := T; {Display seconds to 3 dec places}

end;

-Kirk

------------------------------------------------
Kirk B. Spadt ksp...@keyware.com
Keyware Systems, Inc.
570 Lindsey Drive (610) 964-9530
Radnor, PA 19087 (610) 964-0543 fax

George Mealer

unread,
Jul 12, 1995, 3:00:00 AM7/12/95
to
fel...@ix.netcom.com (Bob Feller ) wrote:

>Another "newbie" question....

>I'm looking for a routine that will calculate a time duration based on
>to Date/Time values. I'm converting a VB app that used the DateDiff
>function (returns the difference of 2 dates in seconds), and there
>doesn't seem to be a Delphi equivalant.

>Thanx in advance,

>Bob

The Delphi TDateTime type is actually just a float.

Get your two date/times using whatever function you want to use (Now,
Time, Date, whatever)...subtract them as normal. You can break the
result down using DecodeDate or DecodeTime. Alternately, you can
change it to a string using one of the Date/Time Format functions.

Geo
--
George Mealer
gme...@best.com


0 new messages