Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare 2 struct tm on multiplatform

Lets say I have two

struct tm

I need to compare them in Linux, in Linux kernel and in Windows. What is the best way to make cross-platform check?

By "compare" I mean finding out what date is bigger. For example - I get date at this moment and compare it to date of some account expired.

like image 505
RedCollarPanda Avatar asked Apr 08 '26 08:04

RedCollarPanda


1 Answers

You could convert them with mktime to time_t and then calculate difference with difftime:

time_t t1 = mktime(tm1);
time_t t2 = mktime(tm2);
double diffSecs = difftime(t1, t2); // If positive, then tm1 > tm2
like image 170
user694733 Avatar answered Apr 10 '26 21:04

user694733



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!