How do you compare current time, without using Alarm

I am using Arduino Uno and Ds1307 RTC time.

I am having RTC time running. I have variable like Hr_ontime , Min_ontime
Hr_offtime and Min_offtime

i would like to turnon the relay between Hr_ontime :min_time & Hr_offtime: min_offtime

#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

void setup() {
  Wire.begin();
  Serial.begin(9600);
  setDateTime(); //MUST CONFIGURE IN FUNCTION
}

void loop() {
  printDate();
  delay(1000);
}

void setDateTime() {

  byte second =      45; //0-59
  byte minute =      12; //0-59
  byte hour =        4; //0-23
  byte weekDay =    2; //1-7
  byte monthDay =    22; //1-31
  byte month =       4; //1-12
  byte year  =       14; //0-99

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero); //stop Oscillator

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekDay));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));

  Wire.write(zero); //start

  Wire.endTransmission();

}

byte decToBcd(byte val) {
  // Convert normal decimal numbers to binary coded decimal
  return ( (val / 10 * 16) + (val % 10) );
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val / 16 * 10) + (val % 16) );
}

void printDate() {

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

  //print the date EG   3/1/11 23:59:59
  Serial.print(monthDay);
  Serial.print("/");


  Serial.print(month);
  Serial.print("/");

  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

}

calculate minutesOfDay then compare in an if-condition

int a =0;

if (((a ==0) && (Hr_ontime == hour) && (Min_ontime == minute))) {
(turn relay on here)
a = 1;
}

if (((a ==1) && (Hr_offtime == hour) && (Min_offtime == minute))) {
(turn relay off here)
a = 0;
}

Or like StefanL38 said with calculating minutes of the day to replace checking hour and minute.

Your sample code doesn’t include any of the variables you mention and seems largely irrelevant to your question, other than accessing a RTC module.

However to answer your question directly, assuming an active LOW relay…

int time = hour * 60 + minute;
int onTime = Hr_ontime * 60 + min_time;
int offTime = Hr_offtime * 60 + min_offtime;
bool relayState = time >= onTime && time < offTime;
digitalWrite(relayPin, relayState ? LOW : HIGH);

This will work better than comparing equality of on and off times, since if you turn on the Arduino during the ON period, or adjust the on/off times while it is running, the relay will always be set correctly.