Found it! This is how


#1

It took me all afternoon to figure it out, but in the end I came up with a nice and clean solution. May I say: elegant?
(I am from the Netherlands, so I used a local date format ddmmyyyy.)

I spent a lot of time thinking of a solution like the bmi calculating function, but that was going nowhere. It took me a while to realize that secondsSince1970 was a variable, and that the solution was to create a new variable.

I skipped the var from the book but not untill my last version, because I used it to check the output for today’s date.
First time, I added 86400 sec (for 1 day), only to check if I got tomorrows date. When that worked out, I changed it to 4 mil.
After I finished and looked at the solutions posted here, I changed 4 with zero’s for the beautiful 4e6. I want to remember this one, because first time I added one zero to much, so I jumped a year ahead :slight_smile:

#include <stdio.h>
#include <time.h>

int main(int argc, const char * argv[])
{ 
    //create new var with 4 mil secs more than today (Time() returns today)
    long fourMilMoreSeconds = time(NULL) + 4e6;
       
    struct tm then;
    localtime_r(&fourMilMoreSeconds, &then);
    printf("Wait for 4 mil secs. The date will be %d-%d-%d.\n", then.tm_mday, then.tm_mon+1, then.tm_year+1900);

    
    return 0;
}

output:

Wait for 4 mil secs. The date will be 16-9-2013.