I was looking for similar topic here, but sadly I wasn't able to find anything helpful.
Problem with my application in C++ is that I need to compute the difference in seconds between two date times given in string structure.
I already cut the string structures into specific day, month etc values. So I started testing the tm
structure given in <ctime>
library.
I wrote simple code:
tm dat1, dat2;
time_t t1, t2;
dat1.tm_mday=3;
dat1.tm_year=2012-1990;
dat1.tm_mon=1-1;
dat2.tm_mday=3;
dat2.tm_year=2003-1990;
dat2.tm_mon=3-1;
t1 = mktime(&dat1);
t2 = mktime(&dat2);
double m = difftime(t1, t2);
cout << m << "\n";
which is sadly giving my an error: returning -1 value in mktime() function
.
For the first time I also filled fields tm_sec, tm_min, tm_hour
but there was also the same error. Right now I am wondering if the fields tm_yday
and tm_wday
are necessary to use mktime()
function?
If yes is there simple way to compute them, because my input looks like "27.07.2012 18:52:00".
Thanks for help, and have a nice day!