hilltop
asked on
Looking for DateDiff Equivalent. Must make app time limited trial..
Hi I am looking for ways to make my C++ app a time limited trial. Any suggestion would be great. I generally use the VB DateDiff, but I see no equivalent in C++. It would be nice to have sample code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Back to difftime. How could I structure a date in the format 2/13/2006 to a time_t and then do the datediff..
Use mktime() to convert struct tm to time_t
ASKER
Could you explain why this doesnt work?
#define TIME_LIMIT ((double)86400 * 30)
struct tm timeinfo;
//'memset(&stm,0,sizeof(st m));
timeinfo.tm_year = 2006 - 1900; // subtract 1900
timeinfo.tm_mon = 2 - 1; // January == 0
timeinfo.tm_mday = 10;
//long * crap =1139813215;
time_t start_time = mktime(&timeinfo);
// Some time later...
time_t curr_time = time(NULL);
// Calculate the time difference (in seconds)
double crap = difftime(curr_time, start_time);
if (crap > TIME_LIMIT) {
printf("%d > %d\n",difftime, TIME_LIMIT);
return 0;
}
printf("%d Huh %d\n",start_time, curr_time);
return 0;
#define TIME_LIMIT ((double)86400 * 30)
struct tm timeinfo;
//'memset(&stm,0,sizeof(st
timeinfo.tm_year = 2006 - 1900; // subtract 1900
timeinfo.tm_mon = 2 - 1; // January == 0
timeinfo.tm_mday = 10;
//long * crap =1139813215;
time_t start_time = mktime(&timeinfo);
// Some time later...
time_t curr_time = time(NULL);
// Calculate the time difference (in seconds)
double crap = difftime(curr_time, start_time);
if (crap > TIME_LIMIT) {
printf("%d > %d\n",difftime, TIME_LIMIT);
return 0;
}
printf("%d Huh %d\n",start_time, curr_time);
return 0;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>Could you explain why this doesnt work?
Your format strings are a bit off, that should be
printf("%ud > %ud\n",crap, TIME_LIMIT);
printf("%ud Huh %ud\n",start_time, curr_time);
Your format strings are a bit off, that should be
printf("%ud > %ud\n",crap, TIME_LIMIT);
printf("%ud Huh %ud\n",start_time, curr_time);
ASKER
Thanks I used an INI class and the following code
int main(int argc, char* argv[])
{
#define TIME_LIMIT ((double)86400 * 30)
time_t curr_time = time(NULL);
CIniReader iniReader("MintDNS.ini");
CIniWriter iniWriter("MintDNS.ini");
time_t start_time;
int gettm = iniReader.ReadInteger("Enc oding", "Style", 25);
start_time = gettm;
if (gettm == 777){
start_time = curr_time;
}
if (gettm == 111){
start_time = time(NULL);
iniWriter.WriteInteger("En coding", "Style", (DWORD)start_time);
start_time = iniReader.ReadInteger("Enc oding", "Style", 25);
}
double crap = difftime(curr_time, start_time);
if (crap > TIME_LIMIT) {
printf("Expired\n");
return 0;
}
printf("%d seconds past\n",crap);
return 0;
}
int main(int argc, char* argv[])
{
#define TIME_LIMIT ((double)86400 * 30)
time_t curr_time = time(NULL);
CIniReader iniReader("MintDNS.ini");
CIniWriter iniWriter("MintDNS.ini");
time_t start_time;
int gettm = iniReader.ReadInteger("Enc
start_time = gettm;
if (gettm == 777){
start_time = curr_time;
}
if (gettm == 111){
start_time = time(NULL);
iniWriter.WriteInteger("En
start_time = iniReader.ReadInteger("Enc
}
double crap = difftime(curr_time, start_time);
if (crap > TIME_LIMIT) {
printf("Expired\n");
return 0;
}
printf("%d seconds past\n",crap);
return 0;
}
SYSTEMTIME s1={2003,11,0,28,12/*hours
printf("%f\n",DT_PeriodsBe
would retrieve the days elapsed between both time stamps.
For more general information, see http://www.codeproject.com/datetime/datetimedisc.asp ("Date and Time in C++")