Day elapsed since today from a given date My function calculates days elapsed from the current date.  Input is fixed.  I will get vector.

Please comment on this.

static bool daysElapsed(const std::vector&lt;char&gt;&amp; vec,int&amp; val)
{       
    std::string str(vec.begin(),vec.end());
    char *pos;// whose value is set by the function to the next character in str after the numerical value.
    int l = strtol(str.c_str(),&amp;pos,10); // Its intention we don’t check till which length strtol converted
    if ((errno == ERANGE &amp;&amp; l == LONG_MAX) || l &gt; INT_MAX)      return false;
    if ((errno == ERANGE &amp;&amp; l == LONG_MIN) || l &lt; INT_MIN)      return false;

    int year = l/10000;
    int month = (l%10000)/100;
    int date = l%100;

    struct std::tm a = {0,0,0,date,
        month-1,   //Month (0 – 11; January = 0).
        year-1900  //Year (current year minus 1900).
    }; 
    struct std::tm b;               

    time_t rawtime;
    time (&amp;rawtime);                // Get the current calendar time UTC !-&gt; Do not rely on this time, Convert to local time first
    localtime_s (&amp;b,&amp;rawtime);     
    time_t x = std::mktime(&amp;a);
    time_t y = std::mktime(&amp;b);
    if ( x != (std::time_t)(-1) &amp;&amp; y != (std::time_t)(-1) ) // Ensure both time are valid
    {
        double difference = std::difftime(y, x) / (60 * 60 * 24);           
        std::cout &lt;&lt; "difference = " &lt;&lt; difference &lt;&lt; " days" &lt;&lt; std::endl;
    }
    else
        return false;

    return true;


}
It's weird to take a std::vector&lt;char&gt; instead of a std::string.  If you must take a std::vector&lt;char&gt;, then make two overloaded versions of the function, where the vector variant calls the string variant.

You never use the val parameter.  You probably meant to use it to return the computed result?  However, the computed difference is a double.

strtol() returns a long, but you assign it to an int.  Then you check if that int exceeds INT_MAX or is less than INT_MIN — which is impossible by definition.  Comparing an int with LONG_MAX and LONG_MIN is similarly nonsensical.  Really, all you want to do is check whether errno is non-zero.

You seem to expect the input in YYYYMMDD format, but you don't do any validation other than checking for overflow or underflow.  There are plenty of 8-digit numbers that shouldn't be valid dates.

Unfortunately, the localtime_s() function is Windows-only.  POSIX has localtime_r(), whose arguments are in the other order, but Windows doesn't support it.  You'll probably need an #ifdef _WIN32.

When testing for the validity of x and y, put the early-return failure case first.  That's just a better pattern for error handling, because the successful case doesn't have to be indented another level.