Weekdays using fortification date

Is there a way to get only no. days of the week between two increase dates.

Further I receive only calendar days.

date begin_dt(2011,Aug,3);
date end_dt(day_clock::local_day());
days duration=end_dt-begin_dt;

std::cout<<"calendar days between begin & end date are: "<<duration<<std::endl;
+2
source share
2 answers

Perhaps the easiest way is to run day_iterator from start to finish:

#include <iostream>
#include <boost/date_time.hpp>
int main()
{
    using namespace boost::gregorian;

    date begin_dt(2011,Aug,3);
    date end_dt(day_clock::local_day());
    days duration=end_dt-begin_dt;

    std::cout<<"calendar days between begin & end date are:" << duration << '\n';

    int cnt=0;
    for(day_iterator iter = begin_dt; iter!=end_dt; ++iter)
    {
        if(    iter->day_of_week() !=  boost::date_time::Saturday
            && iter->day_of_week() !=  boost::date_time::Sunday)
            ++cnt;
    }
    std::cout << "of them " << cnt << " are weekdays\n";
}
+4
source

1 2 , . , 7, 2 . . 6 (), . , .

+1

Source: https://habr.com/ru/post/1530742/


All Articles