Go Premium for a chance to win a PS4. Enter to Win

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

VAR for Time value ?

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
RaVen_2001
Asked:
RaVen_2001
1 Solution
 
ITugayCommented:
Hi RaVen_2001,
why do not use TDateTime?
0
 
RaVen_2001Author Commented:
TDateTime wont accept values over 23:59:59 ?
But maybe u can change this, I don't know.
0
 
JaymolCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jswebyCommented:
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
 
ITugayCommented:
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
 
geobulCommented:
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
 
ITugayCommented:
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
 
RaVen_2001Author Commented:
Well, this integer thing is what I'm using right now, it seems that there is no better solution, Thanks anyway
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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