Henry Olive 5 Posted May 8, 2022 Good Day, procedure TDm.BackUpTimerTimer(Sender: TObject); var MyTime, BackUpStart,BackUpEnd : TTime; begin MyTime := Now; BackUpStart := dm.SettingBACKUPHOUR.AsDateTime; // which is 20:30 BackUpEnd := BackUpStart + EncodeTime(0,30,0,0); // which is 21:00 if ((MyTime >= BackUpStart) and (MyTime <= BackUpEnd)) then // this code doesnt work BackUp; end; Can somebody please help Thank You Share this post Link to post
Mark- 29 Posted May 8, 2022 (edited) Hello, If you made the code: MyTime := EncodeTime(20,45,0,0); BackUpStart := EncodeTime(20,30,0,0); // which is 20:30 BackUpEnd := BackUpStart + EncodeTime(0,30,0,0); // which is 21:00 The "if" works so something in the first three lines is amiss. I suspect "dm.SettingBACKUPHOUR.AsDateTime" is returning a full date AND time. TTime is a TDateTime. Remove the date portion if present. Good luck, Mark Edited May 8, 2022 by Mark- Share this post Link to post
Henry Olive 5 Posted May 8, 2022 (edited) Thank You Mark, dm.SettingBACKUPHOUR = Varchar(5) and the value = '20:30' Edited May 8, 2022 by Henry Olive Share this post Link to post
Mark- 29 Posted May 8, 2022 (edited) OK, so what is the problem? Did you examine the value of "BackUpStart" in the debugger? Edited May 8, 2022 by Mark- Share this post Link to post
Henry Olive 5 Posted May 8, 2022 Eventhough the time is between 20:30 21:00 below code doesnt work if ((MyTime >= BackUpStart) and (MyTime <= BackUpEnd)) then i check MyTime, BackUpStart, BackUpEnd all of them are correct when debugging if ((MyTime >= BackUpStart) then // this works but both with BackUpEnd doesnt work Share this post Link to post
Mark- 29 Posted May 8, 2022 (edited) If you set the time values, per the code I used, the "if" does work. Which leads back to "BackUpStart := dm.SettingBACKUPHOUR.AsDateTime; // which is 20:30". If you replace it with: BackUpStart := EncodeTime(20,30,0,0); // which is 20:30 "if" does work. Right? Back to "BackUpStart := dm.SettingBACKUPHOUR.AsDateTime;". Later; I am wondering if the debugger inspector knows it is defined as TTime and truncates the date portion for display. Not sure that is possible. If you change BackUpStart to TDateTime, does it display the same value in the debugger? Edited May 8, 2022 by Mark- Share this post Link to post
Uwe Raabe 2057 Posted May 8, 2022 1 hour ago, Henry Olive said: Eventhough the time is between 20:30 21:00 below code doesnt work Probably because Now contains the date and the time, while EncodeTime uses an implicit date of 0. You may have better results with MyTime := Time; // uses the time part only BackUpStart := dm.SettingBACKUPHOUR.AsDateTime; // which is 20:30 BackUpEnd := BackUpStart + EncodeTime(0,30,0,0); // which is 21:00 Share this post Link to post
Mark- 29 Posted May 8, 2022 (edited) 15 minutes ago, Uwe Raabe said: Probably because Now contains the date and the time, while EncodeTime uses an implicit date of 0. I wondered that also. Time and Now put the same value in MyTime, according to the debugger inspector. I "thought" the compiler would remove the date porition of Now because MyTime is TTime not TDateTime. But if I turn off the "Visualizer" in the watch properties and look at MyTime (Now) as a float it is 44689.4217036343. And MyTime (Time) as a float it is 0.422856287... So for me, use Time and for safety "Frac" the result of "dm.SettingBACKUPHOUR.AsDateTime;" BackUpStart := Frac(dm.SettingBACKUPHOUR.AsDateTime); Edited May 8, 2022 by Mark- Share this post Link to post
Uwe Raabe 2057 Posted May 8, 2022 6 hours ago, Mark- said: and for safety "Frac" There is already TimeOf for that. Share this post Link to post
Mark- 29 Posted May 8, 2022 1 hour ago, Uwe Raabe said: There is already TimeOf for that. Yes, which is: Result := Frac(AValue); Share this post Link to post
Henry Olive 5 Posted May 9, 2022 I changed MyTime to TTime and now my code works. Thank You SO MUCH Mark, Uwe Share this post Link to post