Sure, use 'mktime()' for that
struct tm a;
struct tm b;
time_t t1 = mktime(&a);
time_t t2 = mktime(&b);
if (t2 > t1) {
// t2 is more recent than t1, thus b is more recent than a
}
The 'time_t' value returned represents the number of seconds til 1/1/1970 up to the 'tm' date.
From the docs:
mktime returns the specified calendar time encoded as a value of type time_t. If timeptr references a date before midnight, January 1, 1970, or if the calendar time cannot be represented, the function returns –1 cast to type time_t.
Main Topics
Browse All Topics





by: brettmjohnsonPosted on 2006-03-18 at 09:05:50ID: 16225286
Use mktime() to convert struct tm to time_t, then use difftime() to compare them.