[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

Small Question of Time(4RWilson, or anyone)

I'm using this:

var
StartTime, EndTime, CloseTime : TDateTime;

...
StartTime := NOW;
....
EndTime   := NOW;
....
CloseTime := NOW;



Label1.caption := FormatDateTime(HH:MM:SS, EndTime-StartTime);

This works great. But
Label2.caption := FormatDateTime(HH:MM:SS, CloseTime+EndTime);

adds the hours, minutes, and seconds together (as expected). I need a method to add the total time of Starttime with EndTime.
Ex: if Start time is 00:00:02 and end time is 00:00:10 then label2 should show 00:00:12 ( I need this to show corrctly also if the time goes into the minutes section, or the hour section.

Is there a way to do this?
0
JPersinger
Asked:
JPersinger
  • 4
  • 3
1 Solution
 
MadshiCommented:
How can starttime be 00:00:02 ??? I mean 00:00:02 looks like a difference to something, it doesn't look like an absolute time... Hmmm... Perhaps I don't understand what you want?
0
 
seredaCommented:
Simple answer (in case you want to add actually _time_, not date):

ResultTime := TDateTime (Double (Time1) + Frac (Double (Time2)));

Where Time1 is original time and Time2 - time to add.

Actually, this is bad style, because add operation is not defined for time and date. Compiler does not respond an error because TDateTime is actually Double, meaning a number days since 30-DEC-1899 (afair) (fractional part means hours, minutes, secs, etc).

So you may play with them as you wish, only understand what the numbers mean.
0
 
JPersingerAuthor Commented:
Madshi -
I'm sorry for not being clear. The 00:00:02 is the total difference from EndTime (EndTime := NOW - which gets recorded when the second button is clicked) minus the StartTime (StartTime := NOW - which gets recorded when the first button gets clicked) value. So What I need is how to take the time (value) from the EndTime value (in this case 00:00:02) and add it to the value of the CloseTime value (which would get recorded when a third button gets clicked). So it should equal this: Mylabel.caption = CLoseTime + EndTime;
Hope this helps...In the meantime I'm going to try Sereda's answer and see what happens.
Thanks


0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
seredaCommented:
Can you please give more details of this button clicking stuff? ;)
I think that the correct answer lies in correct question.
Correct time operations are:
DifTime = Time2 - Time1 (gives difference between dates in days, multiply this by 86400 to get it in secods)
and
Time2 = Time1 + DifTime

so i'll take a wild guess - you need something like
MyLabel.Caption := CloseTime + (EndTime - StartTime) ???

Otherwise i don't see much reason in the task.
0
 
JPersingerAuthor Commented:
so i'll take a wild guess - you need something like
MyLabel.Caption := CloseTime + (EndTime - StartTime) ???

Yes. Your right...The button click task is acting like a stop watch.

Scenero:
Press (or click)the stop watch and the race starts (StartTime). Click the stop watch again to record the end of lap one (EndTime). Click the stop watch again and you get the time it took to make it around the track on lap one and the total time of the race (CloseTime).

In real life:
I have an applcaition that will launch another application. I need to find out how long it takes to load this second application (endtime-starttime) so the user can begin using it. The user will click a few radio buttons and checkboxes on this second application and then close the applcation. I need to measure that time too (CloseTime+EndTime).  when complete I need it to tell me 1) How long it took to bring the app up, 2) configure it, and then 3) close it (closing it may take longer because of the data that is being saved out..does this help?
0
 
seredaCommented:
Okay, now it's clear.
The important part here is that you need to distinguish absolute time measurement (like NOW) and time difference (like EndTime-StartTime).
Here, you will have to make three absolute measurements:
StartTime := NOW;
EndTime := NOW;
App_Closed := NOW;

and then,
 EndTime - StartTime = number of days
 it took to start the application

 App_Closed - EndTime = number of days
 application worked

 App_Closed - StartTime = total
0
 
JPersingerAuthor Commented:
For this section, do I still need to divide the number of days by 86400 to get the seconds (since I really need the seconds, and hope the ap doesn't take days :)

App_Closed - EndTime = number of days
 application worked/86400 ?

 
0
 
seredaCommented:
you are almost right
you need to multyply :)
number_of_seconds := number_of_days * 86400;
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now