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
Medium Priority
270 Views
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
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
• 4
• 3
• 2
• +3

LVL 2

Accepted Solution

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

ID: 1389741
1436?
0

LVL 2

Expert Comment

ID: 1389742
On day = 23 hours 56 minutes or 1436 minutes
0

Author Comment

ID: 1389743

how can i compute with different dates
0

Author Comment

ID: 1389744

how can i compute with different dates
0

Author Comment

ID: 1389745

how can i compute with different dates
0

LVL 15

Expert Comment

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

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

ID: 1389748
hi all,

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

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

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

Author Comment

ID: 1389751
Thank you very much for the answer
0

## Featured Post

Question has a verified solution.

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

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
Course of the Month8 days, 5 hours left to enroll