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

x
?
Solved

VAR for Time value ?

Posted on 2001-06-29
8
Medium Priority
?
187 Views
Last Modified: 2010-04-04
Is there an VAR type where you can store a time value with more then 24 hours, like 1029:31:42 ? (1029 hours, 31 minutes and 42 seconds) or do i just have ot create one and if, how do I oragnize the stuff with the 60' system (after 60s raise minutes and so on)?
0
Comment
Question by:RaVen_2001
[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
8 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6238079
Hi RaVen_2001,
why do not use TDateTime?
0
 

Author Comment

by:RaVen_2001
ID: 6238085
TDateTime wont accept values over 23:59:59 ?
But maybe u can change this, I don't know.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6238124
Try this, the first bit being copied directly from the Delphi Help file.....

  TTimeStamp = record
    Time: Integer;      { Number of milliseconds since midnight }
    Date: Integer;      { One plus number of days since 1/1/0001 }

  end;


try it with this....

  Showmessage(IntToStr(DateTimeToTimestamp(Now).Time));
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:jsweby
ID: 6238150
The time part of a TDateTime is a fraction of 1, so you are correct in that it cannot hold more than 24 hours. However, if the integer part of the number (i.e. the date) starts at zero, then you can store the number of days in the integer part of the number and the hours as normal in the fraction. e.g.

3 days, 12 hours = 3.5
2 days, 6 hours  = 2.25

J.
0
 
LVL 9

Accepted Solution

by:
ITugay earned 120 total points
ID: 6238183
Ok,

The main problem of TDateTime is precision in seconds.

var
  D: TDateTime;
begin
  D := StrToDateTime('10:45:59');
  Caption := FormatDateTime('hh:mm:nn',D);

in this sample Caption = 10:49:45!

You can keep your time in integer variable, it would be more precision.
Here is a sample how to convert time to integer and then back:

const
  OneSec = 1;
  OneMin = OneSec * 60;
  OneHour = OneMin * 60;

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  D: Integer;
  H,M,S: Integer;
begin
  D := 5 * OneHour + 20 * OneMin + 32 * OneSec;

  H := D div OneHour;
  M := (D - H * OneHour) div OneMin;
  S := (D - H * OneHour - M * OneMin) div OneSec;


  Caption := IntToStr(H)+':'+IntToStr(M)+':'+IntToStr(S);

end;

------
Igor.
0
 
LVL 17

Expert Comment

by:geobul
ID: 6238245
Hi,
What about:

type
 TTime = type TDateTime;

function StringToTime(const S: string): TTime;
begin
  result := StrToDateTime(S);
end;

function TimeToString(const Time: TTime): string;
var
  Hours: integer;
begin
  Hours := Trunc(Time) * 24 + StrToInt(FormatDateTime('hh',Time));
  result := IntToStr(Hours) + ':' + FormatDateTime('mm:ss',Time);
end;

example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := TimeToString(Now - StrToDate('28.06.01'));
end;

Regards, Geo
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6238393
Hi Geo,

I'm afraid that TTime will cause the same problems with precision in seconds.

TTime decalred as
type TTime = type TDateTime;

TDateTime and TTime is not usefull when we need to calculate seconds :-(

------
Igor.
0
 

Author Comment

by:RaVen_2001
ID: 6238553
Well, this integer thing is what I'm using right now, it seems that there is no better solution, Thanks anyway
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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

661 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