Solved

Difference between two TDatetimes - formatted as string

Posted on 2003-11-12
3
429 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

636 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