twenty_sleven Posted February 11, 2012 Share Posted February 11, 2012 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. Quote Link to comment Share on other sites More sharing options...
FHannes Posted February 12, 2012 Share Posted February 12, 2012 Now returns a TDateTime timestamp, which is a double, so why not just compare those? Quote Link to comment Share on other sites More sharing options...
twenty_sleven Posted February 12, 2012 Author Share Posted February 12, 2012 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 Quote Link to comment Share on other sites More sharing options...
FHannes Posted February 12, 2012 Share Posted February 12, 2012 Obviously... You have to actually store something in it first... And also, you can't compare a string to a number... Quote Link to comment Share on other sites More sharing options...
twenty_sleven Posted February 12, 2012 Author Share Posted February 12, 2012 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! Quote Link to comment Share on other sites More sharing options...
FHannes Posted February 12, 2012 Share Posted February 12, 2012 [wiki=GetSystemTime]GetSystemTime[/wiki] does not return the current time. Quote Link to comment Share on other sites More sharing options...
twenty_sleven Posted February 12, 2012 Author Share Posted February 12, 2012 Mhmmm, right. So how would I go about converting a time of day (Military time works fine) into the double Timestamp of Now to compare the two? Quote Link to comment Share on other sites More sharing options...
FHannes Posted February 12, 2012 Share Posted February 12, 2012 ... Now returns a Double timestamp which represents the current time of day. Quote Link to comment Share on other sites More sharing options...
twenty_sleven Posted February 13, 2012 Author Share Posted February 13, 2012 Yes, so the current time of day is 40951.8039540625... (7:18P.M) I want to to say... When Now = 7:20 (or is > 7:19 && < 7:21) that is does X. I tried the Normal TimetoStr(Now) and replaced Now with similar double values... but it just seems like some really complicated code. ha Quote Link to comment Share on other sites More sharing options...
FHannes Posted February 13, 2012 Share Posted February 13, 2012 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] Quote Link to comment Share on other sites More sharing options...