Board index » delphi » please help with tDateTime problem

please help with tDateTime problem

i need to enter a date and the program should be able to tell me exacly
how many days and/ or hours had gone by until present date/time....

so far i keep getting impossible numbers, any idea on how to do this?

any help is greatly appreaciated!

thanks!

please e-mail answer too.

--
Uri Fridman

urif...@yahoo.com
u...@afek.co.il

"...the further we go, the older we grow,
the more we know, the less we show..."

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6

mQBtAzZXFiEAAAEDAJfbBmE5Yc9E3OoEF8Ku6vSlDdzen3e9uhdctdN6Hsz4MnhY
0zkxuYEnW5RBpj4nn/SxyLtqwtHBVUMdHlwkuTsRnN1U3Tjy+adjI23GbIY4iXKV
j0mgDGr5XV73w+WjjQAFEbQXVXJpIDx1cmlmcmlkQHlhaG9vLmNvbT4=
=VVEj
-----END PGP PUBLIC KEY BLOCK-----

 

Re:please help with tDateTime problem


{SET CH TO 'D' FOR DAYS AND 'H' FOR HOURS}

function DTDiff(ch:char;SDT,EDT:TDateTime):LongInt;
var
X:Single;
begin
     if ch='d' then
        X:=Trunc(EDT-SDT)
     else
         X:=Round((EDT-SDT)*24);
     Result:=Round(X);
end;

Quote
Uri Fridman wrote:
> i need to enter a date and the program should be able to tell me exacly
> how many days and/ or hours had gone by until present date/time....

> so far i keep getting impossible numbers, any idea on how to do this?

> any help is greatly appreaciated!

> thanks!

> please e-mail answer too.

> --
> Uri Fridman

> urif...@yahoo.com
> u...@afek.co.il

> "...the further we go, the older we grow,
> the more we know, the less we show..."

> -----BEGIN PGP PUBLIC KEY BLOCK-----
> Version: 2.6

> mQBtAzZXFiEAAAEDAJfbBmE5Yc9E3OoEF8Ku6vSlDdzen3e9uhdctdN6Hsz4MnhY
> 0zkxuYEnW5RBpj4nn/SxyLtqwtHBVUMdHlwkuTsRnN1U3Tjy+adjI23GbIY4iXKV
> j0mgDGr5XV73w+WjjQAFEbQXVXJpIDx1cmlmcmlkQHlhaG9vLmNvbT4=
> =VVEj
> -----END PGP PUBLIC KEY BLOCK-----

Re:please help with tDateTime problem


In article <37774CCD.95913...@afek.co.il>, Uri Fridman <u...@afek.co.il>
writes:

Quote
>i need to enter a date and the program should be able to tell me exacly
>how many days and/ or hours had gone by until present date/time....

>so far i keep getting impossible numbers, any idea on how to do this?

TDateTime is the type used and this consists of whole number days and decimal
days.

It can be encoded and decoded or you can handle it yourself if you are not
concerned ewith the calender values (ie you just want elapsed times.

Now gives you a value for er er er now <gg>

You could calculate elapsed days and hours as :-

var
  PreviousDate, DateTimeDiff : TDateTime;
  HoursElapsed, Days, Hours : integer;
begin
  PreviousDate := StrToDate(Edit1.Text);

  DateTimeDiff := Now - PreviousDate;
  HoursElapsed := trunc(DateTimeDiff * 24);
  Days := HoursElapsed div 24;
  Hours := HoursElapsed mod 24;
  Label1.Caption := Format('%d days %d hours', [Days, Hours]);
end;

You could obviously collapse the code - I have left it expanded for your
clarity.

Similar calculations are used when timing code execution to test for the
fastest  code.

Alan Lloyd
alangll...@aol.com

Other Threads