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..
}
}
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.
}