Compare tm’s
struct tm Tm1 = {0};
struct tm Tm2 = {0};
strptime("2020-08-29 11:05:13", "%Y-%m-%d %H:%M:%S", &Tm1);
strptime("2020-08-29 11:05:16", "%Y-%m-%d %H:%M:%S", &Tm2);
if (mktime(&Tm1) >= mktime(&Tm2)) //Larger values of mktime() are more recent in time
{
printf("Tm1 is more recent than Tm2\n");
}
else
{
printf("Tm1 is older than Tm2\n");
}
or with strptime() check
struct tm Tm1 = {0};
struct tm Tm2 = {0};
if (strptime("2020-08-29 11:05:13", "%Y-%m-%d %H:%M:%S", &Tm1) == NULL)
printf("strptime Failed\n");
if (strptime("2020-08-29 11:05:16", "%Y-%m-%d %H:%M:%S", &Tm2) == NULL)
printf("strptime Failed\n");
if (mktime(&Tm1) >= mktime(&Tm2)) //Larger values of mktime() are more recent in time
{
printf("Tm1 is more recent than Tm2\n");
}
else
{
printf("Tm1 is older than Tm2\n");
}
Get time difference in seconds
double TimeDifferenceSeconds;
TimeDifferenceSeconds = difftime(mktime(&Tm1), mktime(&Tm2)); //Value1 - Value2
