title: Comparing two timestamp strings in C++
body: <p>I have two timestamps stored as string variables.  The timestamps are in the format dd/mm/yyyy-hh:mm:ss
  I am trying to find the difference in seconds between the two timestamps (ignoring the dates).</p>
  
  <p>(I haven't assigned strings to a and b but they hold a timestamp each)</p>
  
  <p>It always outputs 0 for the number of seconds difference and I can't work out why.</p>
  
  <pre><code>std::string a, b; // hold timestamps
  struct tm t, t1;
  double seconds;
  
  t.tm_hour = stoi(a.substr(11,2)); // stoi() cast substring to int
  t.tm_min = stoi(a.substr(14,2));
  t.tm_sec = stoi(a.substr(17,2));
  
  t1.tm_hour = stoi(b.substr(11,2));
  t1.tm_min = stoi(b.substr(14,2));
  t1.tm_sec = stoi(b.substr(17,2));
  
  seconds = difftime(mktime(&amp;t1), mktime(&amp;t));
  std::cout&lt;&lt;seconds;
  </code></pre>