Hi all, bit of a c++ newbie and hoping you might be able to help me with a problem.
I'm trying to calculate the elapsed time between two dates using difftime, however I keep getting an elapsed time of 0. Can anyone see where I'm going wrong? Any help greatfully recieved!
Cheers.
#include <iostream>
#include <time.h>
using namespace std;
int main ()
{
time_t rawtime,rawtime2;
struct tm * timeinfo;
struct tm * timeinfo2;
int year=2010, month=9 ,day=23;
double dif;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
timeinfo->tm_year = year - 1900;
timeinfo->tm_mon = month - 1;
timeinfo->tm_mday = day;
timeinfo->tm_min =30;
mktime ( timeinfo );
cout << "First date " << asctime (timeinfo) << endl;
time ( &rawtime2 );
timeinfo2 = localtime ( &rawtime2 );
mktime( timeinfo2 );
cout << "Second date " << asctime (timeinfo2) << endl;
dif = difftime(rawtime2,rawtime);
cout << "The time difference between the two dates is " << dif << endl;
}