Jump to content
twenty_sleven

What type of data is time?

Recommended Posts

After checking out the internets it seemed to be class data, being that Scar has times separated by... well, colons. Unfortunately, in order to do proper "if" statements I need to know it's correct variable (String doesn't cut it! >.<)

 

program New;
var
  sCurrentTime: String;
begin
sCurrentTime:=    TimeToStr(Now);
WriteLn(TimeToStr(Now));
if
 sCurrentTime < 9:15:40 AM then
    WriteLn('Zomgosh it works!  ');
 end.
end.

Link to comment
Share on other sites

I tried using a double value to hold it and it always returned... 12:00:00 AM.

 

program New;
var
  sCurrentTime: String;
  dTime: Double;
begin
sCurrentTime:=    TimeToStr(Now);
WriteLn(TimeToStr(Now));
WriteLn(sCurrentTime);
WriteLn(TimeToStr(dTime));

end.

 

With output of...

 

Successfully compiled (32 ms)
9:32:53 PM
9:32:53 PM
12:00:00 AM
Successfully executed (15 ms)

 

When trying dTime = TimeToStr(Now) It returned a type Mismatch (as it should) I simply want to be able to hold the value of the current time and compare it to another easily, would I have to break the string down to 9,32,53 and then rate it against another double? Thanks

Link to comment
Share on other sites

Now returns a TDateTime timestamp, which is a double, so why not just compare those?

 

I want to be able to have a function run at any time of the day. For example, make the computer return the time of day every 20 minutes between 8A.M to 2P.M... And I know I can't compare strings, And I tried using...

 

 
Mili := GetSystemTime;

ConvertTime(Mili,H,M,S);
WriteLn(H);
WriteLn(M);
WriteLn(S);

 

But for whatever reason that's calibrated off 2 hours, 12 minutes, and 30 seconds or so... Sorry for the bucket of questions, always trying to learn!

Link to comment
Share on other sites

You can use DecodeTime to do calculations with individual time components:

 

[scar]var

Time1, Time2: TDateTime;

H, M, S1, S2, MS: Word;

 

begin

Time1 := Now;

Wait(2000);

Time2 := Now;

DecodeTime(Time1, H, M, S1, MS);

DecodeTime(Time2, H, M, S2, MS);

WriteLn('It is ' + IntToStr(S2 - S1) + ' seconds later than before the wait call.');

end.[/scar]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...