C++ difftime bug?

When I run the difftime() function with the dates shown, it returns 74 days. However, when I check it, Excel returns 73 days. Does anybody know if this is a bug or if I'm doing something wrong?

Thanks.

#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
using namespace std;

time_t lint_time(std::string &string_time) // "MM/DD/YYYY"
{
const char *char_time = string_time.c_str();
int day, month, year;

sscanf_s( char_time, "%2d/%2d/%4d", &month, &day, &year );

tm tm_time = { 0, 0, 0, day, month, year - 1900 };

return mktime( &tm_time );
}

int days_between(time_t first, time_t second)
{
return difftime( second, first ) / (60 * 60 * 24);
}

int main()
{
string today("04/19/2017");
string later("07/01/2017");

cout << days_between(lint_time(today), lint_time(later)) << endl;
// cout << ( int_time(later) - int_time(today) ) / (60*60*24) << endl;
// same result
return 0;
}

Topic archived. No new replies allowed.