Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Datetime diference?

Posted on 2002-07-20
6
Medium Priority
?
251 Views
Last Modified: 2010-04-04
I have two datetime strings in 2 edit boxes. How can I find the number of hours between these two values even if it exceeds 24 hrs.

eg: 7/21/2002 1:15:25 AM minus 7/22/2002 2:15:28 PM

thnks
0
Comment
Question by:drnadeem
[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
6 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 150 total points
ID: 7167199
Very simple:

function HoursDifference(StartDateTime, EndDateTime: String): Integer;
var d1,d2: TDateTime;
begin
  DateSeparator:='/';  ShortDateFormat:='mm/dd/yyyy';
  TimeSeparator:=':';  LongTimeFormat:='h:m:s';
  d1:=StrToDateTime(StartDateTime);
  d2:=StrToDateTime(EndDateTime);
  Result:=Round((d2-d1)*24);
end;

//DEMO:
//---------

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('The difference between '+Edit1.Text+' and '+Edit2.Text+' is '+
              IntToStr(HoursDifference(Edit1.Text, Edit2.Text))+' hours.');
end;
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7167371
drdaem if you have Delphi6 then you can use the DateUtils unit and the HoursBetween function
there are also DaysBetween, SecondsBetween, ... check out the DateUtils unit :)
0
 

Expert Comment

by:Chalo
ID: 7167933
Try this:
Edit3.Text := DateTimeToStr((StrToDateTime(Edit1.Text) -              StrToDateTime(Edit2.Text))/24);
0
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!

 
LVL 7

Expert Comment

by:Cynna
ID: 7168103
Chalo,

Did you tried out your proposed answer?

I see you are new to EE. Proposing an answer is generally not considered a good practice here. But if you propose it anyway, you should be sure it works, and it's a different one than other poster suggested. In this case, neither is true.
In the future, please consider posting a comment and let the asker choose the right answer for himself.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7170133
only a b-grade for a perfect work ?

:-(
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7170220
:-) ...

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

664 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