Date comparison to find which is bigger in C

前端 未结 4 1270
说谎
说谎 2020-12-19 03:48

I want to know how to find which is bigger date using a c program

kindly help me out plz....

Thanks

4条回答
  •  隐瞒了意图╮
    2020-12-19 04:22

    You can use the difftime function:

    #include 
    #include 
    
    int main(void) {
      time_t date1, date2;
      // initialize date1 and date2...
    
      double seconds = difftime(date1, date2);
      if (seconds > 0) {
        printf("Date1 > Date2\n");
      }
    
      return 0;
    }
    

    If your dates are not of type time_t, you can use the function mktime to convert them.

提交回复
热议问题