simple 24h time calc

Hi all

I have some logical problem !!
The code below contains start_time 2230 and stop_time 0730
But wath can i do when i have times like start_time 2230 and stop_time 0430 ???

current_time <= end_time ?? wont match with 0430 ??

thanks

// boundaries, these won't change
const int start_time = 22 * 100 + 30;
const int end_time = 7 * 100 + 30;

// variable declaration
int current_time;

// a whole value to compare with
current_time = hours * 100 + minutes;

// inside the boundaries?
if (current_time >= start_time || current_time <= end_time) {
    if (something_happens) {
        // duty now..
    }
}

Instead of "stop_time" do you mean "end_time"?

yes sorry i mean end_time

If end_time less than start_time represents end_time the following day, just add 24 hours to end_time.

Hello,

I don't know if this is possible but you could do something like (sorry only know this in std C at the mo):

#include <time.h>

time_t start_datetime,
end_datetime,
curent_datetime;

start_datetime = time(NULL); // Then start processing ....
end_datetime = time(NULL); // When processing finishes.

current_date = time(NULL); // Called when appropriate

if(current_datetime >= start_datetime && current_datetime <= end_datetime)
{
// Do something
// When comparing time you nearly always need to compare dates too.
// The time() function converts date/times into longs - this makes it easy
// to do comparisons.
}