?
Solved

Difference between two TDatetimes - formatted as string

Posted on 2003-11-12
3
Medium Priority
?
431 Views
Last Modified: 2010-05-18
I need a fuction which takes a StartTime (TDateTIme) and EndTime (TDateTIme) and returns the difference formatted as such 'Hours:Mins:Secs'

function GetDiffStr(End, Start: TDateTime): String
begin
 result:=
end;
0
Comment
Question by:shaneholmes
3 Comments
 
LVL 2

Accepted Solution

by:
Trekker72 earned 200 total points
ID: 9735742
how about using this

 MilliSecondSpan(StartTime, EndTime) div 1000

to send to the TimeString function from yesterday

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20794890.html
0
 
LVL 4

Expert Comment

by:kabix
ID: 9735784
Check out: http://www.bsdg.org/swag/DELPHI/0258.PAS.html

function GetDiffStr(End, Start: TDate): String
begin
 DateSeparator:= '-';
 ShortDateFormat:= 'm/d/yyyy';
 aDay:=StrToDate('9-23-1976');
 bDay:=strToDate('10-23-1976');
 result:= intToStr(daysBetween(aDay,bDay)));
end;

Also you could check: http://beta.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20672746.html

If it helped please dont forget to accept the answer.
0
 
LVL 5

Expert Comment

by:Darth_helge
ID: 9739114
A TDateTime datatype is nothing but a wrapper around a double datatype.
this means that taking the difference between two TDateTime variables is just substract the one from the other

Diff := Date1 - Date2;

remember to have the 'DateUtils' in your uses clause

function GetDiffStr(End, Start: TDateTime): String
var
Diff: TDateTime;
begin
Diff := Start - End;
result:= TimeToStr(Diff);
end;


TimeToStr converts a TDateTime variable to a string, but ONLY the time part. If you want the exact difference with days too, use the DateTimeToStr(Diff) instead!

hope this helps

Helgesen
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question