# Getting the unix seconds for the next 24 hours in future?

I’m trying to find the unix epoch seconds for the next 24 hours in the future and having some trouble. If I could even find the unix seconds of the next hour I should be able to find the hours in the future, but so far I haven’t been able to do so.

Here’s the code I’m using:

``````// include header file for time function
#include <TimeLib.h>

#include "RTClib.h"

void setup() {
Serial.begin(115200);
}

void loop()  {

//DateTime now = rtc.now();

// Tuesday, October 29, 2019 9:38:19 PM
DateTime now=1572385099;

for (int i = 0; i <= 24; i++) {

tmElements_t tm;

tm.Second = 0;
tm.Hour = 0;
tm.Minute = 0;
tm.Day = now.hour();
tm.Day = now.day();
tm.Month = now.month();
tm.Year = now.year();
time_t nextMakeTime =  makeTime(tm);

Serial.println(now.day());
Serial.println(now.month());
Serial.println(now.year());

Serial.println(nextMakeTime);
Serial.println("---");
}

delay(2000);
}
``````

The DateTime is part of the RTC library, and is just unix seconds.

The above code returns -1400417792 for the nextMakeTime, which is odd.

I don’t imagine anyone has any ideas?

Aha, fixed by subtracting 1970 from the year:

tm.Year = now.year()-1970;

I'm planning to then add 3600 seconds to each hour to get 24 hours into the future, and then convert those seconds to unix timestamps.

If anyone sees a more efficient way of doing so, please let me know.

1 day = 86400 seconds:

``````unsigned long secPerDay = 86400UL;
tomorrow = DateTime now + secPerDay;
``````

TimeLib has constants like SECS_PER_DAY https://github.com/PaulStoffregen/Time/blob/f11f6fc1de7f08ce8c3ce9946be0836b037a58b2/TimeLib.h#L65

here are some snippets working with TimeLib and C time functions https://arduino.stackexchange.com/questions/55248/how-to-parse-20180810t143000z-to-time-t