Millis overflow

I use a lot of Arduino devices in my smart home and often need it to time things over a much longer time period than the millis() function allows. To get around this limitation, my projects and code work with seconds instead of milliseconds and this allows my code to work over >49,000 days without issues. The code I use to achieve this is:

// Global variables
unsigned long millis_new; // time now in millis
unsigned long millis_old; // previous time in millis
unsigned long rollovers = 0;
unsigned long seconds = 0;

void setup()
{
}

// Function to track seconds over long time period
void Timers()
{
millis_new = millis();
if (millis_new < millis_old)
rollovers++;
millis_old = millis_new;
seconds = (0x100000000 * rollovers) + (millis_new / 1000);
}

// Main Program loop
void loop()
{
Timers();

// The rest of my code

Serial.print("Seconds: ");
Serial.println (seconds);
}

Post split from an old topic.
Please do not hijack old topics

When you post code please use code tags as described in Read this before posting a programming question

As to your statement

often need it to time things over a much longer time period than the millis() function allows.

This is only a problem if you want to time periods longer than 49 days. Is that the problem that you are trying to solve ?