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

x
?
Solved

Formula on computing time

Posted on 1999-07-19
12
Medium Priority
?
270 Views
Last Modified: 2010-04-06
for example i started in 9:30am and end in 2:45pm in that
the same date how can i get the total time used from
9:30 to 2:45, how many hours & minutes is used?
can you give me a formula for that.

specially on computing the time from this day and ends
the other day.
ex. from 7:00am todays date and end with
     8:am tomorrows date.

0
Comment
Question by:mvalez
[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
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 200 total points
ID: 1389740
declare two TDateTime type variables:  var  s, e: TDateTime
declare timeUsed:  var timeUsed: Double;
assign the startTime to s
assign endTime to e
timeUsed := (e - s) * 1436  
 {this give you the time used calculated in minutes, you can convert it to hour by dividing it with 60 ....  }

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1389741
1436?
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1389742
On day = 23 hours 56 minutes or 1436 minutes
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:mvalez
ID: 1389743
thanks for the answer...

how can i compute with different dates
0
 

Author Comment

by:mvalez
ID: 1389744
thanks for the answer...

how can i compute with different dates
0
 

Author Comment

by:mvalez
ID: 1389745
thanks for the answer...

how can i compute with different dates
0
 
LVL 15

Expert Comment

by:simonet
ID: 1389746
mvalez,

kjteng's method works, but there's a much more straightforward way of calculating the information you want. It's to use GetTickCount instead.

The only 2 drawbacka of GetTickCount is: 1)if the machine is turned off somewhere in the middle of the process, the count is reset; 2) if the process runs continuously for over 49.7 days, the GetTickCount will also reset! However, so far, I don't believe Windows 95 is able to be run for that long (the longer my Win95 has been up is 6 days, and 29 days for the office's NT machine).

Using GetTickCount you get the difference between the first and the second call in milliseconds. Converting that to minutes, hours, days, etc, is pretty straighforward:

var
  t1, tt : DWORD;
begin
  t1 := GetTickCount;
  // run your process for as long as 49.7 days!
  tt := (GetTickCount - t1) div 1000;
  // Now tt holds the elapsed time in seconds


for the elapsed time in:
seconds --> use tt
minutes:seconds --> use tt div 60 and tt mod 60

and so on.

if you prefer this solution over the one currently proposed answer, you are allowed to reject the proposed answer.  
 
Yours,

Alex
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1389747
What do you mean by "different date"?
The above method should work even if e and s are not in the same day.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1389748
hi all,

whats about this

Var Start,Diff : TDateTime;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Start := Now;
end;


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Diff := Now - Start;
  ShowMessage(IntToStr(Trunc(Diff))+' Days '+TimeToStr(Diff));
end;

meikl
0
 
LVL 15

Expert Comment

by:simonet
ID: 1389749
mvalez,

as we can see, there are several ways of doing what you want, because it's pretty trivial stuff. I suggest you choose the method that serves you best and let us know.

Yours,

Alex
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1389750
I think kretschz.. is the best and easier solution
0
 

Author Comment

by:mvalez
ID: 1389751
Thank you very much for the answer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

715 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