function IsInTime(xTime: TDateTime; Hour1, Min1, Hour2, Min2: Integer): Boolean;
var
xHour, xMin, xSec, xMSec: Word;
begin
DecodeTime(xTime, xHour, xMin, xSec, xMSec); // this Procedure is declared in SysUtils
if (Hour2 < Hour1) or ((Hour2 = Hour1) and (Min2 < Min1)) then Inc(Hour2, 24);
Hour1:= Hour1 * 60 + Min1;
Hour2:= Hour2 * 60 + Min2;
xHour:= xHour * 60 + xMin;
Result:= (xHour >= Hour1) and (xHour <= Hour2);
end;