hi all , im trying to compare two time values , but im unable to display the correct result , the retval returns -1 for both d1 and d2 , i suppose the mktime is the convert the values into seconds since EPOCH . any idea as to where im wrong ?
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <iostream.h>
time_t to_seconds(const char *time)
{
struct tm storage={0,0,0,0,0,0,0,0,0};
char *p=NULL;
time_t retval=0;
p= (char *)strptime(time,"%H:%M",&storage);
if(p==NULL)
{
retval=0;
}
else
{
retval=time(&storage);
}
return retval;
}
int main(void)
{
char *stoptime="01:05";
char *currenttime="15:15";
time_t d1=to_seconds(stoptime);
time_t d2=to_seconds(currenttime);
cout<<"time comparison:<<stoptime<<currenttime;
if(d2>d1)
{
cout<<"currentdate is larger\n";
}
if(d2<=d1)
{
cout<<"currentdate is smaller\n";
}
}