shaneholmes
asked on
Difference between two TDatetimes - formatted as string
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;
function GetDiffStr(End, Start: TDateTime): String
begin
result:=
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
function GetDiffStr(End, Start: TDate): String
begin
DateSeparator:= '-';
ShortDateFormat:= 'm/d/yyyy';
aDay:=StrToDate('9-23-1976
bDay:=strToDate('10-23-197
result:= intToStr(daysBetween(aDay,
end;
Also you could check: http://beta.experts-exchange.com/questions/20672746/Days-between-two-dates.html
If it helped please dont forget to accept the answer.