Possible arduino IDE bug

Hi all,
today I came here to post a solution to a problem, but hopefully it will help somebody else one day.

I wanted to schedule various things to happen every minute, hour, day etc. using a DS3232 real time clock and the time.h library.

All was going well until I got to the daily schedule as I used the following code:

if(currentTime>lastCleanup+60*60*24) {
//do stuff
}

it turns out that 606024 evaluates to 20864, which is wrong.

The code works fine when I substitute 86400.

That has nothing to do with the IDE.
606024 = 86400. BUT 86400 does not fit into a 16-bit integer so you get weird result.
Change 606024 to 86400L

Pete

Please, don't keep in suspense! YoU'Ll be keeping us from knowing how to fix the problem!

Perhaps you should have used

if(currentTime>lastCleanup+60UL*60*24) {
//do stuff
}

Thanks Pete, hopefully it will help someone one day.

Presumably you are comparing long integer times, in which case another thing you need to fix is that the comparison will fail when the time wraps around.
Use this:
if(currentTime - lastCleanup > 86400L) {
//do stuff
}

Pete

As the time is in seconds since 1970, a quick calculation says time will wrap around in approx 136 years. Or is there something I'm missing?

He assumed that the current time is from millis(), not your RTC converted to a unix time.

Ooops. Brain not in gear again.

Pete