This is one way.
<strong>#include</strong> <iostream>
<strong>#include</strong> <ctime>
<strong>int</strong> <strong>main</strong>()
{
<strong> struct</strong> std::tm a = {0,0,0,24,5,104}; /* June 24, 2004 */
<strong> struct</strong> std::tm b = {0,0,0,5,6,104}; /* July 5, 2004 */
std::time_t x = std::<strong>mktime</strong>(&a);
std::time_t y = std::<strong>mktime</strong>(&b);
<strong> if </strong>( x != (std::time_t)(-1) && y != (std::time_t)(-1) )
{
<strong>double</strong> difference = std::<strong>difftime</strong>(y, x) / (60 * 60 * 24);
std::<strong>cout</strong> << std::ctime(&x);
std::<strong>cout</strong> << std::ctime(&y);
std::<strong>cout</strong> << "difference = " << difference << " days" << std::<strong>endl</strong>;
}
<strong> return</strong> 0;
}
/* my output
Thu Jun 24 01:00:00 2004
Mon Jul 05 01:00:00 2004
difference = 11 days
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314