Good afternoon.
I'm having difficulty with handling dates in C. I'm using the time.h library to tinker with dates.
I need to create a struct tm
that contains the date of the day (example) 1/29/1950, and then store its time_t
value in a variable.
The problem is that I create the structure, I assign the day / month / year values to their respective variables ( tm_mday
, tm_mon
and tm_year
), but when I use the mktime()
function, it returns -1.
Code snippet:
data->tm_mday = dia;
data->tm_mon = mes - 1;
data->tm_year = ano - 1900;
segs = mktime(data);
I was not having any problems with this solution for recent dates.
What could be happening?
EDIT 1 : Running a loop to see how far mktime () works, I noticed that it works until the value of tm_year equals 70. Below that it returns -1 ...
EDIT 2 : Doing some more tests, I noticed that the value that mktime () returns is the number of seconds since 12/31/1969 10:00 PM. Any date before that I can not create with this structure.