user70607: i'm working on a project where i need to run a function for 20 minutes and the function writes to memory using EEPROM every minute. How can i make the function run for 20 minutes, i was thinking of using millis to measure the time between starting time and current but i'm afraid that when the millis rolls over and the the difference in time becomes negative my program will break and my function will run forever . Is there any way to make a function run for a certain amount of time, or will millis handle the rollover if we use unsigned variables for all variables for millis();

user10794: See this answer for an explanation. Using unsigned variables, and subtracting will definitely work.
Not only will unsigned variables not become negative (by their very nature) but the rollover will be handled smoothly and accurately.

user32037: Another way to solve this problem is using cronAlarm. It can provide precise control on timings and you can schedule your job also. https://www.arduino.cc/reference/en/libraries/cronalarms/

70607: <p>i'm working on a project where i need to run a function for 20 minutes and the function writes to memory using EEPROM every minute. How can i make the function run for 20 minutes, i was thinking of using millis to measure the time between starting time and current but i'm afraid that when the millis rolls over and the the difference in time becomes negative my program will break and my function will run forever . Is there any way to make a function run for a certain amount of time, or will millis handle the rollover if we use unsigned variables for all variables for millis();</p>
 10794: <p>See <a href="https://arduino.stackexchange.com/a/29842/10794">this answer</a> for an explanation. Using unsigned variables, and <em>subtracting</em> will definitely work.</p>
<p>Not only will unsigned variables not become negative (by their very nature) but the rollover will be handled smoothly and accurately.</p>
 32037: <p>Another way to solve this problem is using cronAlarm. It can provide precise control on timings and you can schedule your job also. <a href="https://www.arduino.cc/reference/en/libraries/cronalarms/" rel="nofollow noreferrer">https://www.arduino.cc/reference/en/libraries/cronalarms/</a></p>
