title: C++ Days between given date and today´s date
body: <p>I have a function called <code>int differenceDatesInDays(string&amp; date)</code>.
  This function should get a string value as a date (YYYY-MM-DD) and compare it with today´s date.</p>
  
  <p>I don´t know if there is already something inside the STL, i could not find a matching algorithm. I just found out that boost has a solution for this, but i don´t want to use boost.</p>
  
  <p>So, this is my code so far:</p>
  
  <pre><code>int differenceDatesInDays(string&amp; date) {
      string year = date.substr(0, 4);
      string month = date.substr(5,2);
      string day = date.substr(8, string::npos);
  
      int y = stoi(year);
      int m = stoi(month);
      int d = stoi(day);
  
      time_t time_now = time(0);
      tm* now = localtime(&amp;time_now);
  
      int diffY = y - (now-&gt;tm_year + 1900);
      int diffM = m - (now-&gt;tm_mon + 1);
      int diffD = d - (now-&gt;tm_mday);
  
      int difference = (diffY * 365) + (diffM * 30) + diffD;
  
      return difference;
  }
  </code></pre>
  
  <p>I don´t know how to find out if the month has 30, 31 or 28 days. </p>