# RTC question

How can I proceed to compare the current time vs 2 time boundary limits. I want to keep a relay pin high in a specific moment. I mean, the first time boundary limit 11:30 and the second boundary limit is 14:10. Now, if I wanna read 13:20, the program says “it´s inside the boundary, I´ll keep the relay pin high”. I find examples like clock alarms, but it only works when the target time is equal to the current time. This manner, whatever reason the equipment gets out of energy at 11:29 and turn alive 11:40, my sketch would be useless because the trigger wouldn´t work.

If this is every day, change the time to minutes past midnight.
So 11:30 is 690 and 14:10 is 850.
13:20 is 800 which is in between, so you get a hit:

``````if (minSinceMid > 690 && minSinceMid < 850) {
// Do something
}
``````

I find examples like clock alarms, but it only works when the target time is equal to the current time.

If you have same variables like startHour, currentHour, endHour, startMinute, currentMinute, and endMinute, you can create startTime, currentTime, and endTime, by multiplying hour by 60 and adding minute.

Then,

``````  if(currentTime >= startTime && currentTime <= endTime)
{
// It's time to do something
}
``````

However, I think you are going about it wrong. Having a pin high for a period of time does NOT require that you continually turn the pin on. What you have is a time that you want to turn the pin on, and a time that you want to turn the pin off.

KeithRB:
If this is every day, change the time to minutes past midnight.
So 11:30 is 690 and 14:10 is 850.
13:20 is 800 which is in between, so you get a hit:

``````if (minSinceMid > 690 && minSinceMid < 850) {
``````

// Do something
}

Yeeeess!!! that´s it!!! Really smart way!!

It compares 2 boundary time when we don´t set round hours limits!! Perfect!!

Perfect!!

Not really, if the aim is simply to turn a pin on at one time and off at another. If that is the case, as you stated, then only the boundaries are important.