title: difference between two date in C
body: <p>I am trying to get the difference between two date by using below C code.</p>
  
  <p>but code always giving difference 0. Help me to where i am making mistake.</p>
  
  <p>I am using gcc compiler under linux.</p>
  
  <pre><code>#include &lt;stdio.h&gt;  
  #include &lt;time.h&gt;       
  int main ()
  {
    struct tm start_date;
    struct tm end_date;
    time_t start_time, end_time;
    double seconds;
  
    start_date.tm_hour = 0;  start_date.tm_min = 0;  start_date.tm_sec = 0;
    start_date.tm_mon = 10; start_date.tm_mday = 15; start_date.tm_year = 2013;
  
    end_date.tm_hour = 0;  end_date.tm_min = 0;  end_date.tm_sec = 0;
    end_date.tm_mon = 10; end_date.tm_mday = 20; end_date.tm_year = 2013;
  
    start_time = mktime(&amp;start_date);
    end_time = mktime(&amp;end_date);
  
    seconds = difftime(end_time, start_time);
  
    printf ("%.f seconds difference\n", seconds);
  
    return 0;
  }
  </code></pre>
  
  <p><strong>EDIT :</strong>
  @qchen answer helped lot to solve my problem. one more doubt is there. Below was my update. From the answer</p>
  
  <pre><code>  start_date.tm_hour = 0;  start_date.tm_min = 0;  start_date.tm_sec = 0;
    start_date.tm_mon = 10-1; start_date.tm_mday = 18; start_date.tm_year = 2013-1876;
  
    end_date.tm_hour = 0;  end_date.tm_min = 0;  end_date.tm_sec = 0;
    end_date.tm_mon = 10-1; end_date.tm_mday = 20; end_date.tm_year = 2013-1876;
  </code></pre>
  
  <p>tm_year is the year since 1900, then why i getting correct output if i replace 1876 with year between 1876 to 2012.</p>