Solved

Difference between two TDatetimes - formatted as string

Posted on 2003-11-12
3
428 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 50 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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