Question: i'm trying to get the number of trading dates between two dates which will only exclude the weekends and won't consider any holidays. I'm using Boost and c++11 standards. 

```
using namespace boost::gregorian;
long dateDifference( string start_date, string end_date ) {

            date _start_date(from_simple_string(start_date));
            date _end_date(from_simple_string(end_date));

            long difference = ( _start_date - _end_date ).days();

            return difference;

        }

```

This just returns the number of days between two dates without considering weekends. Can someone point me in the right direction. I can't seem to figure out the solution. 

Thanks,
Maxx

Answer: 
Just run a day iterator and calculate the weekdays manually:

```
#include <boost/date_time.hpp>

using namespace boost::gregorian;

long dateDifference( string start_date, string end_date ) 
{
    date _start_date(from_simple_string(start_date));
    date _end_date(from_simple_string(end_date));

    // counter for weekdays
    int cnt=0;
    for(day_iterator iter = _start_date; iter!=_end_date; ++iter)
    {
        // increment counter if it's no saturday and no sunday
        if(    iter->day_of_week() !=  boost::date_time::Saturday
            && iter->day_of_week() !=  boost::date_time::Sunday)
            ++cnt;
    }
    return cnt;
}

```

Answer ported from this answer: <https://stackoverflow.com/a/7342989/3187827>
The simplest approach is to use the boost::gregorian::day\_of\_week() function and iterate through every day between your start date and your end date, incrementing only when it's not a Saturday nor a Sunday.

A more efficient approach would be to iterate from start\_date to the next Monday (say), iterate from end\_date to the previous Monday, then with a simple division find out how many week-ends you've got in between.

Finally, a "real world" solution would involve finding proper calendar data with the holidays that apply to your case, and integrate it with your algorithm.